2012-07-06 82 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