2014-03-03 67 views
0

我想重写客户端网站的网址,但它不按预期工作。htaccess重写规则不按预期工作

我无法弄清楚我做错了什么。

RewriteRule ^about/sectionreps/(.*)$ http://myclientssite.com/sectionreps/ [r=301,nc] 

因此,/ sectionreps /将重定向到/ about/sectionreps /但这不是我想要的。

这里是整个文件:

# BEGIN WordPress 
<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteBase/

RewriteRule ^about/sectionreps/(.*)$ http://myclientssite.com/sectionreps/ [r=301,nc] 

RewriteRule ^index\.php$ - [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /index.php [L] 

</IfModule> 

# END WordPress 

所以我的问题是为什么URL重写不会从: http://myclientssite.com/about/sectionreps

http://myclientssite.com/sectionreps/

+0

问题是什么?你只提到你不希望重定向的地方 – covener

+0

oops,编辑我的问题。 – DLaverick

+0

仅仅是为了这个网页吗?或者你可以改变wp-admin内的永久链接结构吗? – Steven

回答

0

试试下面添加以下代码wordpress代码

#start custom redirects 
RewriteCond %{HTTP_HOST} myclientssite.com/about/sectionreps/ [NC] 
RewriteRule ^(.*)$ http://myclientssite.com/$1 [L,R=301] 
Redirect 301/http://www.myclientssite.com/sectionreps/ 
#end custom redirects 
+0

让我知道这是怎么回事 – Und3rTow

+0

这令人遗憾地将它发送到一个永无止境的/ sectionreps/sectionsreps/etc但别担心,只要/ sectionreps重定向到正确的页面,我的客户现在对整个url感到满意。 – DLaverick

0

试试这个代码:

# BEGIN WordPress 
<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteBase/

RewriteRule ^about/sectionreps(/.*)?$ /sectionreps/$1 [R=301,NC,L] 

RewriteRule ^index\.php$ - [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /index.php [L] 

</IfModule> 
# END WordPress 

确保在新的浏览器进行测试。

+0

可悲的是,这没有奏效。由于时间紧迫,我的客户已经达成妥协。 – DLaverick

+0

Well规则在我的测试中有效。 – anubhava

1

您的代码表示/about/sectionreps/*将被重定向到(可能是其他站点)/sectionreps/。不是相反,正如你暗示的(但后来在帖子中反驳)。这是你寻找的重定向吗?

您的代码需要输入URI上的尾部/。这可能是为什么/about/sectionreps不匹配(但/about/sectionreps/应该)。

RewriteRule ^about/sectionreps(/)? /sectionreps [R=301,NC] 

应该完成这项工作。你不需要匹配尾随的东西(.*)$,因为你放弃了它,并且你不需要提供http:bit,因为你在同一个域中。