Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex 如何强制将子域重定向到';https://www.'?_Regex_Apache_.htaccess_Redirect_Https - Fatal编程技术网

Regex 如何强制将子域重定向到';https://www.'?

Regex 如何强制将子域重定向到';https://www.'?,regex,apache,.htaccess,redirect,https,Regex,Apache,.htaccess,Redirect,Https,我想重定向 http://sub.domain.com 及 http://www.sub.domain.com 及 https://sub.domain.com 到 https://www.sub.domain.com 如何在.htaccess中执行此操作? 提前谢谢 还有一个额外的问题,我在哪里可以学到这些?有必要学习它们吗 [你可以看出网络上有很多答案,但大多数答案都是针对主域的,而不是针对子域的。]你可以使用: RewriteEngine on # Redirect sub.doma

我想重定向

  • http://sub.domain.com
  • http://www.sub.domain.com
  • https://sub.domain.com
    • https://www.sub.domain.com
    如何在.htaccess中执行此操作? 提前谢谢

    还有一个额外的问题,我在哪里可以学到这些?有必要学习它们吗

    [你可以看出网络上有很多答案,但大多数答案都是针对主域的,而不是针对子域的。]

    你可以使用:

    RewriteEngine on
    
    # Redirect sub.domain.com to https://www.sub.domain.com
    RewriteCond %{HTTP_HOST} ^sub\.domain\.com$ [NC]
    RewriteRule ^ https://www.sub.domain.com%{REQUEST_URI} [NE,R=301,L]
    
    # Redirect http://www.sub.domain.com to https://www.sub.domain.com
    RewriteCond %{HTTPS} off
    RewriteCond %{HTTP_HOST} ^www\.sub\.domain\.com$ [NC]
    RewriteRule ^ https://www.sub.domain.com%{REQUEST_URI} [NE,R=301,L]
    

    您可以在这里学习Apache配置格式:

    Yes,Yes。事实上,我忘了在问题中加上那个。请编辑您的代码并修复。非常感谢。请告诉我代码的分版,其中一个将重定向到https,另一个将重定向到www?这是为了在不同的子域上使用代码。我在回答中补充了这一点