当且仅当 url 中没有参数 q= 时,如何让 mod_rewrite 执行 RewriteRules?
下面的代码可以处理我的 url 结构,但如果 url 中有参数 q= ,我需要规则不起作用。
我尝试设置一个重写条件(在下面的注释行中)但没有成功,
请帮助!谢谢 :)
Options +FollowSymlinks
RewriteEngine on
# RewriteCond %{QUERY_STRING} q!=(.*)
RewriteRule ^FSD/([^/]+)/([^/]+)/ /index.php?service=$1&type=FSD [NC]
RewriteRule ^ECD/([^/]+)/([^/]+)/ /index.php?service=$1&type=ECD [NC]
RewriteRule ^([^/]+)/([^/]+)/ /index.php?category=$1&subcategory=$2 [NC]
RewriteRule ^([^/]+)/ /index.php?category=$1 [NC]
the below code works to deal with my url structures but i need the rules not to work if there is parameter q= in the url.
i tried to set up a rewritecond (in the commented out line below) without success,
please help! thanks :)
Options +FollowSymlinks
RewriteEngine on
# RewriteCond %{QUERY_STRING} q!=(.*)
RewriteRule ^FSD/([^/]+)/([^/]+)/ /index.php?service=$1&type=FSD [NC]
RewriteRule ^ECD/([^/]+)/([^/]+)/ /index.php?service=$1&type=ECD [NC]
RewriteRule ^([^/]+)/([^/]+)/ /index.php?category=$1&subcategory=$2 [NC]
RewriteRule ^([^/]+)/ /index.php?category=$1 [NC]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的
RewriteCond
的测试模式有点偏离,但您的想法是正确的:请注意,
RewriteCond
仅适用于下一个RewriteRule
,因此,如果您想对所有四个规则执行此排除,则需要复制每个规则上方的RewriteCond
。Your
RewriteCond
's test pattern is a little off, but you got the right idea:Note that the
RewriteCond
only applies to the nextRewriteRule
, so if you want to perform this exclusion for all four of your rules, you'll need to copy theRewriteCond
above each of them.