为什么htaccess的重写规则^富$也匹配^ foobar的$ [英] Why does htaccess RewriteRule ^foo$ also match ^foobar$

查看:147
本文介绍了为什么htaccess的重写规则^富$也匹配^ foobar的$的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想这些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.

这篇关于为什么htaccess的重写规则^富$也匹配^ foobar的$的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆