【问题标题】:301 Redirect adding incorrect extra segments to a url301 重定向将不正确的额外段添加到 url
【发布时间】:2012-04-08 08:35:22
【问题描述】:

我需要 301 将一个 url 的一部分重定向到它的新版本。

我的目标是重定向

www.domain.co.uk/farm/whatever/

www.domain.co.uk/farm_cottages/whatever/

我使用的规则是:

重定向匹配 301 ^/farm/ /farm_cottages/

但由于某种原因,它部分有效,但在最终网址中的 farm_cottages/ 之后附加了 ?/farm/ 即。

www.domain.co.uk/farm_cottages/?/farm/whatever/

这是我的整个重写规则集,因为我相信其中一个重写规则可能会干扰重定向规则。

#redirect /farm/ to /farm_cottages/
RedirectMatch 301 ^/farm/  /farm_cottages/

<IfModule mod_rewrite.c>
RewriteEngine on

# no WWW to WWW
RewriteCond %{HTTP_HOST} !^www.domain.co.uk$ [NC]
RewriteRule ^(.*)$ http://www.domain.co.uk/$1 [R=301,L]

# Force trailing slash on URLs
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://www.domain.co.uk/$1/ [L,R=301]

#Remove index.php
RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]

RewriteCond %{THE_REQUEST} ^[^/]*/index\.php [NC]
RewriteRule ^index\.php(.+) $1 [R=301,L]

</IfModule>

该站点是在 Expressionengine 中构建的,因此 url 的段不代表实际的文件夹 - 不过我认为这无关紧要。

任何想法将不胜感激!谢谢

【问题讨论】:

    标签: apache mod-rewrite redirect http-status-code-301


    【解决方案1】:

    好的,我最终通过以下方式解决了这个问题 - 我希望它可以帮助将来的人:

    RewriteRule ^farm/(.*)$ /farm_cottages/$1 [QSA,R=301,L]
    

    【讨论】:

      猜你喜欢
      • 2016-05-05
      • 2014-04-04
      • 2015-06-24
      • 1970-01-01
      • 2012-10-30
      • 1970-01-01
      • 2021-12-27
      • 1970-01-01
      • 2022-01-08
      相关资源
      最近更新 更多