.htacces重定向(通配符)子文件夹到HTTPS子域


.htacces redirect (wildcard) a subfolder to a https subdomain?

我有一个名为:"polygon"的文件夹,我可以通过以下方式访问:

  • http://website.com/polygon
  • http://www.website.com/polygon

我为这个文件夹创建了子域,也可以通过两种方式访问它:

  • http://polygon.website.com
  • http://www.polygon.website.com

我对这个子域进行了https访问:https://polygon.website.com

我想重定向文件夹和子域,有和没有,www到:https://polygon.website.com

在。htaccess中,我用Cpanel做了一个重定向:

RewriteCond %{HTTP_HOST} ^website'.com$ [OR]
RewriteCond %{HTTP_HOST} ^www'.website'.com$
RewriteRule ^secure'/?(.*)$ "https':'/'/polygon'.website'.com'/$1" [R=301,L]

,但我不能重定向http://(www.?)website.com/polygon到安全url,因为一个循环错误消息…

提前感谢您的帮助!:)

您可以像这样单独排除每个sub1, sub2;

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^sub1'.domain'.com [NC]
RewriteRule ^(.*) - [L]
RewriteCond %{HTTP_HOST} ^sub2'.domain'.com [NC]
RewriteRule ^(.*) - [L]
RewriteCond %{HTTP_HOST} !^www'.domain'.com [NC]
RewriteRule ^(.*) http://www.domain.com/$1 [L,R=301]
</IfModule>

或者明确你只想用RewriteCond

将domain.com重定向到www.domain.com
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain'.com [NC]
RewriteRule ^(.*) http://www.domain.com/$1 [L,R=301]
</IfModule>
参考

https://serverfault.com/questions/391843/htaccess-redirect-non-www-to-www-and-retain-subdomains-from-redirecting