.htaccess 问题
假设我有以下 .htaccess 文件:
RewriteEngine On
RewriteCond %{HTTP_COOKIE} name=value [NC]
RewriteRule ^image01.gif$ http://www.domain.tld/images/partner/image01.gif [NC,QSA]
RewriteCond %{HTTP_COOKIE} name=value [NC]
RewriteRule ^image02.gif$ http://www.domain.tld/images/partner/image02.gif [NC,QSA]
NC
和 QSA
是什么意思?
另外,不是重复相同的 RewriteCond
两次,而是只使用一次并将其应用于两个 RewriteRule
吗?
最后,如果上述 .htaccess 位于 http://www.domain.tld/images/为什么这样的 RewriteRule 不起作用?:
RewriteRule ^image02.gif$ /images/partner/image02.gif [NC,QSA]
或者也许是这样?:
RewriteRule ^image02.gif $partner/image02.gif [NC,QSA]
Say I have the following .htaccess file:
RewriteEngine On
RewriteCond %{HTTP_COOKIE} name=value [NC]
RewriteRule ^image01.gif$ http://www.domain.tld/images/partner/image01.gif [NC,QSA]
RewriteCond %{HTTP_COOKIE} name=value [NC]
RewriteRule ^image02.gif$ http://www.domain.tld/images/partner/image02.gif [NC,QSA]
What do NC
and QSA
mean?
Also, instead of repeating the same RewriteCond
twice is there to use it just once and have it apply to both RewriteRule
s?
Finally, if the above .htaccess is located at http://www.domain.tld/images/ why doesn't a RewriteRule like this work?:
RewriteRule ^image02.gif$ /images/partner/image02.gif [NC,QSA]
Or maybe this?:
RewriteRule ^image02.gif$ partner/image02.gif [NC,QSA]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
方括号选项记录在 RewriteRule 手册页 :
'nocase|NC' (无大小写):
'qsappend|QSA'(查询字符串附加):
据我所知, RewriteCond 指令 影响它们位于 RewriteRule 之前。如果您在主配置文件中设置规则,则可以在文件中编写通用指令和 包含多次,但这不是
.htaccess
文件中的选项,抱歉。你的指令对我有用,尽管你的意思可能是这样的:
你是如何准确测试它的?
The square bracket options are documented in the RewriteRule manual page:
'nocase|NC' (no case):
'qsappend|QSA' (query string append):
As far as I know, the RewriteCond directives affect the RewriteRule they precede. If you were setting rules in the main confing file you could write the common directives in a file and include it several times but that's not an option in
.htaccess
files, sorry.Your directive works for me, although you probably mean this:
How are you testing it exactly?
NC 代表无大小写,这意味着它可以是大写或小写,并且它将带您到同一页面。
QSA 用于查询字符串附加。对此不太确定,但是快速搜索 http://httpd.apache。 org/docs/1.3/mod/mod_rewrite.html 对这个问题有更多的了解。
NC is for No Case, meaning it can be upper or lower case and it will take you to the same page.
QSA is for query string append. Not really sure on this one, however a quick search http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html sheds a bit more light on this one.