【问题标题】:301 Redirect all pages including query strings to main page of new domain301 将包括查询字符串在内的所有页面重定向到新域的主页
【发布时间】:2013-10-24 07:02:10
【问题描述】:

我正在尝试 301 将所有网址(包括带有查询字符串的网址)重定向到新域上的一个页面。

RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?domain1\.com$ [NC]
RewriteRule ^(.*)$ "http://www.domain2.com/" [R=301,L]

问题在于这不会从 URL 中删除查询字符串。 它重定向

domain1.com/?PageAction=VIEWPROD&ProdID=57&HS=1

domain2.com/?PageAction=VIEWPROD&ProdID=57&HS=1

而不是

domain2.com/

【问题讨论】:

    标签: php regex apache .htaccess mod-rewrite


    【解决方案1】:

    使用此规则从结果 URL 中删除查询字符串:

    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^(www\.)?domain1\.com$ [NC]
    RewriteRule ^ http://www.domain2.com/? [R=301,L]
    

    http://www.domain2.com/? 末尾注明?,以去除原始URL 中任何现有的查询字符串。

    参考:Apache mod_rewrite Introduction

    【讨论】:

      猜你喜欢
      • 2013-08-06
      • 2018-08-21
      • 2014-06-13
      • 2016-02-11
      • 2014-09-23
      • 2014-05-30
      • 1970-01-01
      • 1970-01-01
      • 2017-03-04
      相关资源
      最近更新 更多