为什么 htaccess RewriteRule ^foo$ 也匹配 ^foobar$ [英] Why does htaccess RewriteRule ^foo$ also match ^foobar$

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

问题描述

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

I want these URL redirects / forwards:

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

我有这两条 .htaccess RewriteRule 行:

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

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

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

推荐答案

这是一个浏览器缓存问题.我最初的规则是错误的.我将规则更改为上面列出的规则,但是因为我使用的是 HTTP 状态代码 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 状态代码设置为 303(参见其他)会导致浏览器不缓存它.

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

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

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