作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
第一季度 : 如何链接这两个条件使它们if BOTH A AND B, then proceed...
Q2 : 如何让他们遵守下面的所有 rewriteRules 而不仅仅是第一条规则?
RewriteCond %{REQUEST_URI} ^IMAGE-.*$ // if filename starts with IMG- and,
RewriteCond %{REQUEST_FILENAME} !-f // if file does exist, then proceed:
RewriteRule Rule1
RewriteRule Rule2
RewriteRule Rule3
# -- END IF -- STOP HERE -- #
最佳答案
以下是制作 RewriteCond
的一些技巧堆栈适用于多个 RewriteRule
的,按递增排序 WTF's per minute .但这是配置而不是代码,所以这些规则不适用,对吧? :-)
1.环境变量
当你有很多 RewriteCond
's,将它们的结果存储在环境变量中,然后在每个规则中进行测试更加紧凑。
# Your RewriteCond stack.
RewriteCond %{REQUEST_URI} !^IMAGE-.*$ [OR]
RewriteCond %{REQUEST_FILENAME} -f
# Store environment variable.
RewriteRule ^ - [E=TRUE:YEP]
# Assert environment variable in remaining RewriteRule's.
RewriteCond %{ENV:TRUE} =YEP
RewriteRule Rule1
RewriteCond %{ENV:TRUE} =YEP
RewriteRule Rule2
RewriteCond %{ENV:TRUE} =YEP
RewriteRule Rule3
[S]
或
[skip]
标记你可以导致你的整个 block
RewriteRule
是要跳过的。
# Your RewriteCond stack.
RewriteCond %{REQUEST_URI} !^IMAGE-.*$ [OR]
RewriteCond %{REQUEST_FILENAME} -f
# If RewriteCond's match, skip the next RewriteRule.
RewriteRule ^ - [skip=1]
# Otherwise, this rule will match and the rest will be skipped.
RewriteRule ^ - [skip=3]
RewriteRule Rule1
RewriteRule Rule2
RewriteRule Rule3
RewriteCond
的 if 语句。是条件和
RewriteRule
是代码块。
[skip=N]
每次从这组
中添加或删除规则时否
RewriteRule
的。
[skip]
不包括
的标志否 , 数量
RewriteRule
你想申请
RewriteCond
堆栈到。也就是说...如果您包含一对
RewriteCond
在每个
RewriteRule
之前,哦,是的,最后还有一个。
# Your RewriteCond stack.
RewriteCond %{REQUEST_URI} !^IMAGE-.*$ [OR]
RewriteCond %{REQUEST_FILENAME} -f
# If RewriteCond's match, skip the next RewriteRule.
RewriteRule ^ - [skip=1] # succeeded
RewriteRule ^ - [skip=2] # failed
RewriteRule Rule1
RewriteRule ^ - [skip=1] # succeeded
RewriteRule ^ - [skip=2] # failed
RewriteRule Rule2
RewriteRule ^ - [skip=1] # succeeded
RewriteRule ^ - [skip=2] # failed
RewriteRule Rule3
RewriteRule ^ - # no-op to cover for last [skip=2] rule
[skip=1]
当且仅当
RewriteCond
的成功,并且每个
[skip=2]
当且仅当它们失败时,才会处理规则。
RewriteRule
中匹配它的。
# Your RewriteCond stack.
RewriteCond %{REQUEST_URI} !^IMAGE-.*$ [OR]
RewriteCond %{REQUEST_FILENAME} -f
# If RewriteCond's match, prepend bogus marker "M#" to internal URL.
RewriteRule .* M#$0
# All your RewriteRule's test for this marker plus whatever else.
RewriteRule ^M#.*Rule1
RewriteRule ^M#.*Rule2
RewriteRule ^M#.*Rule3
# Finally, don't forget to strip off the bogus marker.
RewriteRule ^M#(.*) $1
RewriteRule
恢复它,对吧?好吧,只有当它被处理时,所以不要让标记 URL 在它被还原之前逃脱这一轮 mod_rewrite 处理。然后你会得到一个404。
关于apache - 多个重写条件 : How to chain them before a set of rules?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5305987/
我是一名优秀的程序员,十分优秀!