.htaccess 问题

发布于 2024-09-29 08:14:49 字数 791 浏览 0 评论 0原文

假设我有以下 .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]

NCQSA 是什么意思?

另外,不是重复相同的 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 RewriteRules?

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

执妄 2024-10-06 08:14:49

方括号选项记录在 RewriteRule 手册页 :

'nocase|NC' (无大小写):

这使得模式不区分大小写,忽略差异
当 Pattern 与当前 URL 匹配时,位于 'AZ' 和 'az' 之间。

'qsappend|QSA'(查询字符串附加):

此标志强制重写引擎附加查询字符串部分
的替换字符串
现有字符串,而不是替换
它。当你想添加更多时使用这个
通过重写将数据写入查询字符串
规则。


据我所知, RewriteCond 指令 影响它们位于 RewriteRule 之前。如果您在主配置文件中设置规则,则可以在文件中编写通用指令和 包含多次,但这不是 .htaccess 文件中的选项,抱歉。


你的指令对我有用,尽管你的意思可能是这样的:

RewriteRule ^image02\.gif$ /images/partner/image02.gif [NC,QSA]

你是如何准确测试它的?

The square bracket options are documented in the RewriteRule manual page:

'nocase|NC' (no case):

This makes the Pattern case-insensitive, ignoring difference
between 'A-Z' and 'a-z' when Pattern is matched against the current URL.

'qsappend|QSA' (query string append):

This flag forces the rewrite engine to append a query string part
of the substitution string to the
existing string, instead of replacing
it. Use this when you want to add more
data to the query string via a rewrite
rule.


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:

RewriteRule ^image02\.gif$ /images/partner/image02.gif [NC,QSA]

How are you testing it exactly?

前事休说 2024-10-06 08:14:49

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文