【发布时间】:2014-06-13 22:44:06
【问题描述】:
我想将http://、http://www.https://www. 和不存在的子域变体重写为https://domain.com。不存在的子域变体可能是http://abc.domain.com 和https://abc.domain.com。更复杂的是,我想保留尾随 URL,并防止重定向现有的子域。并且,一些现有的子域使用 http,而其他子域使用 https。
这是我目前所拥有的:
#don't redirect existing subdomains example1 or example2
RewriteCond %{HTTP_HOST} ^((example1|example2)\.)?domain\.com$
RewriteRule .* - [L]
##redirect http, wildcard subdomains, and www. with appended trailing URLs
RewriteCond %{HTTP_HOST} . [OR]
RewriteCond %{HTTP_HOST} ^www\.domain\.com$ [NC]
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://domain.com/$1 [R=301,L]
提前致谢。
【问题讨论】:
-
如果子域不存在,它不会被 DNS 服务器解析,您的服务器也不会收到任何请求。
-
@anubhava 目前在我的网站上,输入的任何不存在的子域都会解析为顶级网站。所以,
domain.com和fake.domain.com提供相同的内容。 Bluehost 说这不是 DNS 问题,我需要在 htaccess 中编写修复脚本。 -
如果
fake.domain.com解析为domain.com,那么如何将fake.domain.com识别为不存在的子域? -
@anubhava 我试图将任何/所有子域重定向到 domain.com 除了现有的子域——因为我可以识别/指定现有的子域,但不是不存在的子域..
-
好的,请在下面查看我的答案。
标签: .htaccess mod-rewrite redirect https wildcard-subdomain