如何从重定向中排除子域名?

时间:2021-04-05 11:18:27

I have this code to force any URL to be "https://www.":

我有这个代码强制任何URL为“https:// www。”:

#rewrite to WWW:
RewriteCond %{HTTP_HOST} !^(\d+)
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

#Now, rewrite to HTTPS:
RewriteCond %{HTTP_HOST} !^(\d+)
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

I have sub-domains and I do not want any of them to be redirected. What can I do?

我有子域名,我不希望它们中的任何一个被重定向。我能做什么?

1 个解决方案

#1


1  

You can do it all in single rule:

您可以在单一规则中完成所有操作:

RewriteCond %{HTTP_HOST} !^www\. [OR]
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^(?:static\.|subdomain1\.|subdomain2\.|\d+) [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://www.%1%{REQUEST_URI} [L,R=301,NE]

Make sure to clear your browser cache before testing this rule.

在测试此规则之前,请务必清除浏览器缓存。

#1


1  

You can do it all in single rule:

您可以在单一规则中完成所有操作:

RewriteCond %{HTTP_HOST} !^www\. [OR]
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^(?:static\.|subdomain1\.|subdomain2\.|\d+) [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://www.%1%{REQUEST_URI} [L,R=301,NE]

Make sure to clear your browser cache before testing this rule.

在测试此规则之前,请务必清除浏览器缓存。