2

我在我的 htaccess 文件中使用 301 重定向规则将一些旧网址重定向到新网址。但是,在一些重定向中,旧文件名附加到新 url 上,因此我在这些重定向上遇到 404 页面错误。

例如,这是我的重写规则

Redirect 301 /mtrx/motion-control/ http://www.zerolinegolf.com/golf-mtrx-for-the-golfer

但显示的页面是

http://www.zerolinegolf.com/golf-mtrx-for-the-golfermotion-control

这是整个 .htaccess 代码

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

#REDIRECTS

Redirect 301 /videos/ http://www.zerolinegolf.com/videos-2
Redirect 301 /press-releases-2/ http://www.zerolinegolf.com/media
Redirect 301 /mtrx/motion-control/ http://www.zerolinegolf.com/golf-mtrx-for-the-golfer
Redirect 301 /mtrx/pelvis-power/ http://www.zerolinegolf.com/golf-mtrx-for-the-golfer
Redirect 301 /mtrx/mtrx-score/ http://www.zerolinegolf.com/golf-mtrx-for-the-golfer
Redirect 301 /mtrx/recommended-drills/ http://www.zerolinegolf.com/golf-mtrx-for-the-golfer
Redirect 301 /mtrx/ http://www.zerolinegolf.com/golf-mtrx-for-the-golfer

感谢您的帮助。

4

1 回答 1

6

看起来 mod_alias 和 mod_rewrite 可能相互干扰,也可能相互干扰。

请记住,这些Redirect指令将两个路径节点链接在一起。因此,如果您有,请说:

Redirect 301 /mtrx/ http://www.zerolinegolf.com/golf-mtrx-for-the-golfer

该语句还接受:/mtrx/foo/bar/并将其重定向到http://www.zerolinegolf.com/golf-mtrx-for-the-golferfoo/bar/.

您应该切换到 usingRedirectMatchRewriteRule.

对于前者:

RedirectMatch 301 ^/videos/?$ http://www.zerolinegolf.com/videos-2
RedirectMatch 301 ^/press-releases-2/?$ http://www.zerolinegolf.com/media
RedirectMatch 301 ^/mtrx/motion-control/?$ http://www.zerolinegolf.com/golf-mtrx-for-the-golfer
RedirectMatch 301 ^/mtrx/pelvis-power/?$ http://www.zerolinegolf.com/golf-mtrx-for-the-golfer
RedirectMatch 301 ^/mtrx/mtrx-score/?$ http://www.zerolinegolf.com/golf-mtrx-for-the-golfer
RedirectMatch 301 ^/mtrx/recommended-drills/?$ http://www.zerolinegolf.com/golf-mtrx-for-the-golfer
RedirectMatch 301 ^/mtrx/?$ http://www.zerolinegolf.com/golf-mtrx-for-the-golfer

对于 mod_rewrite,您必须在您的 wordpress 规则之前放置这些规则

RewriteRule ^/?videos/?$ http://www.zerolinegolf.com/videos-2 [L,R=301]
RewriteRule ^/?press-releases-2/?$ http://www.zerolinegolf.com/media [L,R=301]
RewriteRule ^/?mtrx/motion-control/?$ http://www.zerolinegolf.com/golf-mtrx-for-the-golfer [L,R=301]
RewriteRule ^/?mtrx/pelvis-power/?$ http://www.zerolinegolf.com/golf-mtrx-for-the-golfer [L,R=301]
RewriteRule ^/?mtrx/mtrx-score/?$ http://www.zerolinegolf.com/golf-mtrx-for-the-golfer [L,R=301]
RewriteRule ^/?mtrx/recommended-drills/?$ http://www.zerolinegolf.com/golf-mtrx-for-the-golfer [L,R=301]
RewriteRule ^/?mtrx/?$ http://www.zerolinegolf.com/golf-mtrx-for-the-golfer [L,R=301]
于 2013-04-23T22:48:34.053 回答