【问题标题】:htaccess 301 redirect from third level domainhtaccess 301 从三级域重定向
【发布时间】:2013-12-09 08:38:47
【问题描述】:

我有一个网站 www.example.com 我有一个三级域 start.example.com,它重定向到

RewriteCond %{HTTP_HOST} ^start.example\.com$ [NC]
RewriteRule ^(.*)$ index.php?start=1&$1

但不知何故,谷歌在搜索中包含了主域到第三级域的页面, 例如

start.example.com/news/ 

所以我想将所有此类链接重定向 301 到主域

start.example.com/news/  =>  www.example.com/news/ 

但保持第一个重定向正常工作。

我该怎么做,请帮忙?

附:第一个重定向仅用于统计,带有类似的网址

start.example.com/?utm_source=whatever&utm_medium=start 

【问题讨论】:

    标签: regex apache .htaccess mod-rewrite redirect


    【解决方案1】:

    你可以试试这两条规则:

    RewriteCond %{HTTP_HOST} ^start\.example\.com$ [NC]
    RewriteRule ^([^/.]*)$ index.php?start=1&$1 [L,QSA]
    
    RewriteCond %{HTTP_HOST} ^start\.example\.com$ [NC]
    RewriteRule !^index\.php$ http://www.example.com%{REQUEST_URI} [L,R=301]
    

    【讨论】:

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