【问题标题】:htaccess rewrite nonexistent wildcard subdomains with and without httpshtaccess 使用和不使用 https 重写不存在的通配符子域
【发布时间】:2014-06-13 22:44:06
【问题描述】:

我想将http://http://www.https://www. 和不存在的子域变体重写为https://domain.com。不存在的子域变体可能是http://abc.domain.comhttps://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.comfake.domain.com 提供相同的内容。 Bluehost 说这不是 DNS 问题,我需要在 htaccess 中编写修复脚本。
  • 如果fake.domain.com 解析为domain.com ,那么如何将fake.domain.com 识别为不存在的子域?
  • @anubhava 我试图将任何/所有子域重定向到 domain.com 除了现有的子域——因为我可以识别/指定现有的子域,但不是不存在的子域..
  • 好的,请在下面查看我的答案。

标签: .htaccess mod-rewrite redirect https wildcard-subdomain


【解决方案1】:

以下是重定向nonexistent subdomains to https://domain.com的方法:

RewriteCond %{HTTP_HOST} !^domain\.com$ [NC]
RewriteCond %{HTTP_HOST} !^(valid1|valid2|valid3)\.domain\.com$
RewriteRule ^ https://domain.com%{REQUEST_URI} [R=301,L,NE]

RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\.
RewriteRule ^ https://domain.com%{REQUEST_URI} [R=301,L,NE]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-09
    • 1970-01-01
    • 1970-01-01
    • 2017-03-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多