【问题标题】:Parked Domain Wildcard 301 Redirects停放域通配符 301 重定向
【发布时间】:2011-07-20 18:37:43
【问题描述】:

我有一系列域名停放在 LAMP 服务器上的一个帐户上,mod_rewrite 可用于值班。我想实现以下目标:

我正在寻找 domain1.com 成为“主人” - 想法是以下重定向应该到位(具有 301 状态以获得最大的 SEO 效益):

domain2.com 重定向到 domain1.com
domain3.com 重定向到 domain1.com
domain2.com/foo/ 重定向到 domain1.com/foo/ domain3.com/foo/ 重定向到 domain1.com/foo/
domain2.com/foo/bar/ 重定向到 domain1.com/foo/bar/
domain3.com/foo/bar/ 重定向到 domain1.com/foo/bar/

等等……

实际上,我想在混合中实现某种通配符,以便 /foo/ 和 /bar/ 的子页面也被重定向到 domain1.com 上的相同 URL

我一直在寻找相关的 .htaccess 文档,但似乎找不到我正在寻找的解决方案。因此,我想知道你们中的任何人是否有一些指点 - 将不胜感激:)

【问题讨论】:

    标签: .htaccess mod-rewrite redirect http-status-code-301


    【解决方案1】:

    如果您的所有域都停在同一主机上,那么以下规则将适用于您:

    Options +FollowSymlinks -MultiViews
    RewriteEngine on
    
    # handles domain2/* -> domain1/* for http
    RewriteCond %{HTTP_HOST} ^(www\.)?domain2.com$ [NC]
    RewriteCond %{SERVER_PORT} =80
    RewriteRule ^(.*)$ http://domain1.com/$1 [R=301,L]
    
    # handles domain2/* -> domain1/* for https
    RewriteCond %{HTTP_HOST} ^(www\.)?domain2.com$ [NC]
    RewriteCond %{SERVER_PORT} =443
    RewriteRule ^(.*)$ https://domain1.com/$1 [R=301,L]
    
    # handles domain3/* -> domain1/* for http
    RewriteCond %{HTTP_HOST} ^(www\.)?domain3.com$ [NC]
    RewriteCond %{SERVER_PORT} =80
    RewriteRule ^(.*)$ http://domain1.com/$1 [R=301,L]
    
    # handles domain3/* -> domain1/* for https
    RewriteCond %{HTTP_HOST} ^(www\.)?domain3.com$ [NC]
    RewriteCond %{SERVER_PORT} =443
    RewriteRule ^(.*)$ https://domain1.com/$1 [R=301,L]
    

    将它们放入您的 DOCUMENT_ROOT 的 .htaccess 文件中。

    【讨论】:

    • 我在 wordpress 网站上使用了您的解决方案。我必须将这些规则高于 Wordpress 规则。 +1
    【解决方案2】:

    对于 domain2.com 和 domain3.com 中的每一个,您都需要一个类似于以下内容的 .htaccess:

    RewriteEngine on
    RewriteRule ^(.*) http://domain1.com/$1 [R=301,L]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-02-22
      • 2015-11-04
      • 2018-10-03
      • 1970-01-01
      • 2020-07-10
      • 1970-01-01
      • 1970-01-01
      • 2018-04-08
      相关资源
      最近更新 更多