【问题标题】:How to exclude subdomains from redirecting?如何从重定向中排除子域?
【发布时间】:2016-03-22 15:14:13
【问题描述】:

我有这段代码可以强制任何 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]

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

【问题讨论】:

  • 也许你认为这是重复的,但没有任何问题同时包含 www 和 https 重定向

标签: regex linux apache .htaccess mod-rewrite


【解决方案1】:

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

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]

确保在测试此规则之前清除浏览器缓存。

【讨论】:

  • 我已经使用了这段代码,但它会将 static.domain.com 重定向到 https://www .static.domain.com
  • 我试过了,但我遇到了内部服务器错误,我认为它导致了一个循环
  • 刚刚修复它,这是一个额外的)。立即尝试
猜你喜欢
  • 2015-11-29
  • 2014-10-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-08-26
  • 1970-01-01
相关资源
最近更新 更多