删除WP多站点.htaccess文件中的尾部斜杠

时间:2013-05-08 20:14:21

标签: .htaccess redirect wordpress trailing-slash

我创建了一个.htaccess文件,其中包含一个站点的重定向,该站点是较大的WordPress多站点安装的一部分。

.htaccess内容从此开始(必要,因为必须为多个站点使用相同的.httacess文件:

RewriteCond %{HTTP_HOST} ^mydomain.com [nc]

然后包含一系列重写,如下:

RewriteRule ^about-my-site$ about [R=301,NC,L]

如果我访问mydomain.com/about-my-site,我就会被正确地重定向到mydomain.com/about 但是,如果我访问mydomain.com/about-my-site/(请注意斜杠),我会收到“找不到网页”错误。

2 个答案:

答案 0 :(得分:1)

将您的RewriteRule更改为

RewriteRule ^about-my-site/?$ about [R=301,NC,L]

答案 1 :(得分:1)

这些规则应该在您的WordPress规则之前,确保重写已开启,并设置重写基础/ -

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} mydomain.com [NC]
RewriteRule ^about-my-site/? about [R=301,NC,L]
</IfModule>

在此测试:http://htaccess.madewithlove.be/

input url
http://mydomain.com/about-my-site/

output url
http://mydomain.com/about

debugging info
1 RewriteEngine On  
2 RewriteBase / 
3 RewriteCond %{HTTP_HOST} mydomain.com [NC]        This condition was met
4 RewriteRule ^about-my-site/? about [R=301,NC,L]   This rule was met, the new url is http://mydomain.com/about
Test are stopped, because of the R in your RewriteRule options. A redirect will be made with status code 301