2012-07-06 79 views
1
$

我想这些URL重定向/转发:

here.com/foo ==> there.com/a/b 
here.com/foobar ==> there.com/c/d 

我有这两个的.htaccess重写规则行:

RewriteRule ^foo$ http://there.com/a/b [R=301,L] 
RewriteRule ^foobar$ http://there.com/c/d [R=301,L] 

但结果是:

here.com/foo ==> there.com/a/b 
here.com/foobar ==> there.com/a/b 

foo也匹配foobar 如何麦它工作?

+1

必须有一些其他的错误。给定的'RewriteRules'正在为我工​​作。 – hjpotter92 2012-07-06 07:01:46

回答

1

这是一个浏览器缓存问题。我最初的规则错了。我将规则更改为上面列出的规则,但由于我使用的是HTTP状态代码301(永久移动),因此浏览器将其缓存并且未从服务器获取新请求。我尝试了Chrome浏览器隐身窗口并发现了此问题。

请注意,将HTTP状态码设置为303(请参阅其他)会导致浏览器不缓存它。

+2

看到这篇文章的更多意见:http://stackoverflow.com/questions/9153262/tips-for-debugging-htaccess-rewrite-rules#9204355 – TerryE 2012-07-06 12:21:30

+0

哇,很多优秀的技巧调试.htaccess在该职位重写规则。谢谢TerryE! – 2012-07-09 14:00:54