【问题标题】:301 redirect code to new folder structure URLs301 将代码重定向到新的文件夹结构 URL
【发布时间】:2016-05-09 11:42:55
【问题描述】:

我在旧网站上使用此重定向:

RewriteCond %{HTTP_HOST} ^(www\.)?oldsite\.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule ^oldfolder(/.*)?$ http://newsite.com/newfolder$1    [L,R=301,NC,NE]

RewriteCond %{HTTP_HOST} ^(www\.)?oldsite\.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule ^(.*)$ http://newsite.com/$1 [L,R=301,NE]

这个重定向代码帮助我:

  • 首先,在我的新网站上将 www 重定向到非 www
  • 其次,将带有oldfolder的oldsite URL重定向到带有newfolder的newsite URL

问题是一些旧的 URL 在其结构上有 index.php 并且重定向是错误的。例如:

oldsite.com/index.php/oldfolder/....

重定向到

newsite.com/index.php/oldfolder/....

但正确的重定向应该是到

newsite.com/index.php/newfolder/.... 或 newsite.com/newfolder/....

如何更改我的重定向代码以正确重定向到我的新文件夹结构 URL?

【问题讨论】:

    标签: php apache .htaccess redirect mod-rewrite


    【解决方案1】:

    您可以使用以下规则从 oldsite/ 重定向到 newsite:

    RewriteCond %{HTTP_HOST} ^(www\.)?oldsite\.com$ [NC]
    RewriteRule ^oldfolder/(.*)$ http://newsite.com/newfolder/$1    [L,R=301,NC,NE]
    

    【讨论】:

      猜你喜欢
      • 2012-03-23
      • 2013-01-07
      • 2014-07-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-13
      • 2015-05-07
      相关资源
      最近更新 更多