为什么htaccess的重写规则^富$也匹配^ foobar的$重写、规则、htaccess、foobar

2023-09-02 09:42:54 作者:"正在输入"

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

I want these URL redirects / forwards:

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

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

I have these two .htaccess RewriteRule lines:

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

也匹配 foobar的 我如何使它工作?

foo is also matching foobar How do I make it work?

推荐答案

这是一个浏览器缓存的问题。我最初有规则的错误。我改变了规则,上面列出的那些,而是因为我使用的HTTP状态code 301(永久移动),浏览器缓存是它,而不是从服务器获取了新的要求。我尝试了Chrome浏览器隐身窗口,发现了问题。

This was a browser caching issue. I initially had the rules wrong. I changed the rules to those listed above, but because I'm using HTTP status code 301 (Moved Permanently), the browser was caching it and not getting the new request from the server. I tried a Chrome Incognito Window and discovered the issue.

请注意,设置HTTP状态code至303(查看其他)会导致浏览器不缓存它。

Note that setting the HTTP status code to 303 (See Other) causes the browser not to cache it.