Why does htaccess RewriteRule ^foo$ also match ^fo

2019-04-16 03:44发布

I want these URL redirects / forwards:

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

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]

But the result is:

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

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

1条回答
Melony?
2楼-- · 2019-04-16 04:40

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.

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

查看更多
登录 后发表回答