mod_rewrite的的RewriteCond - 是必要的只是域部分NC标志?而一些更 [英] mod_rewrite RewriteCond - is NC flag necessary for just domain part? And some more

查看:227
本文介绍了mod_rewrite的的RewriteCond - 是必要的只是域部分NC标志?而一些更的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在的htaccess见过很多次这些类型的规则:

RewriteCond %{HTTP_REFERER} !^http://www.domain.it$ [NC]

RewriteCond %{HTTP_HOST} !^www\.domain\.it$ [NC]

为什么只检查域部分的时候是 NC 标志必要,?

Why is the NC flag necessary, when checking only the domain part?

我注意到浏览器总是在转换域名uppercases为较低的情况下,,所以我看不出有什么的 [NC] 标志usueful对于在这种情况下

I noticed browsers always converts uppercases in domain names into lower cases, so I don't see what the [NC] flag is usueful for in this case.

我的意思是,如果我们检查网址我理解需要 [NC] 标记的原因在Unix系统上, www.domain的剩余部分。 COM / index.html的是不同的文件比 www.domain.com/INDEX.HTML ,但我不明白<$ C的需要$ C> NC 标志,当我们只检查重写规则的域部分。

I mean if we check the remaining part of the url I understand the need for [NC] flag cause on Unix systems www.domain.com/index.html is different file than www.domain.com/INDEX.HTML but I don't understand the need of NC flag when we check only the domain part in the RewriteRule.

既然你花时间来阅读上面的让我也问一个小问题不直接相关的 NC 标志,但仍相关以的RewriteCond

Since you took the time to read the above, let me ask also one minor question not directly related to NC flag, but still related to RewriteCond

两个的RewriteCond 以上工作显示好,我还以为只是一个与斜线点之前将工作(!^ WWW \。域\。它$ ),因为没有斜线点应该是指的任何字符的在正则表达式whilest的 \ 指的点字符,但surpraisingly也是另一种行之有效的,你知道为什么吗?

Both RewriteCond shown above work well, I thought only the one with slash before dots would work (!^www\.domain\.it$) because the dot without a slash should mean 'any char' in regexp whilest the \. means the dot char, but surpraisingly also the other one works well, do you know why?

推荐答案

[NC] 绝对不是强制性的,但建议把它匹配的域。现代浏览器可能会被转换域名小写但对于旧的浏览器和命令行utils的如的wget 卷曲等,所以你不应该总是依赖于客户端发送您小写字母的域名,并保持 [NC]

Having [NC] is definitely not mandatory but it is recommended to have it for matching domains. Modern browsers might be converting domain names to lowercase but what about old browsers and command line utils like wget, curl etc, so you should not always rely on clients sending you lowercase domain name and keep [NC].

关于你的第二个问题匹配任意字符因此它是能够匹配 www.domain.com ,但它也将匹配 WWW的域名-COM 您不想匹配的文本。因此,最好是有 WWW \。域\ .COM

About your 2nd question . matches any character therefore it is able to match www.domain.com but it will also match www-domain-com text which you don't want to match. So it is better to have www\.domain\.com

这篇关于mod_rewrite的的RewriteCond - 是必要的只是域部分NC标志?而一些更的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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