.htaccess重定向问题:自动添加最后一个参数

时间:2016-09-14 06:39:46

标签: php wordpress .htaccess redirect

我想使用htaccess文件重定向某些网址。

我的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>

Redirect /old-post-type/old-parent-post/old-post-slug/ /new-post-type/new-post-slug/

***** Some More URLs *****

# END WordPress

它应该重定向到http://yourwebsitedomain.com/new-post-type/new-post-slug/但是,它会重定向到http://yourwebsitedomain.com/new-post-type/new-post-slug/old-post-slug/

“old-post-slug /”自动添加到最后我不知道为什么?

接受任何建议。

2 个答案:

答案 0 :(得分:0)

我不建议像这样混合mod_aliasmod_rewrite,RewriteRule先运行,然后在Redirect之后再次运行,这会让奇怪的事情发生。只需使用mod_rewrite,在其他规则之前重定向并使用L标志,如下所示:

RewriteEngine On
RewriteBase /
#I put 302, use 301 if permanent redirect is what you are after.
RewriteRule ^old-post-type/old-parent-post/old-post-slug/$ /new-post-type/new-post-slug/ [L,R=302] 
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

只有当你真的必须使用htaccess进行重定向时,就像有人提到wordpress已经具有处理重定向的功能。

答案 1 :(得分:-2)

试试这个:

Redirect 301 /old-post-type/old-parent-post/old-post-slug/ http://your-domain.com/new-post-type/new-post-slug/

这应该有效。 301代表“永久移动”。