当且仅当 url 中没有参数 q= 时,如何让 mod_rewrite 执行 RewriteRules?

发布于 2024-09-14 07:47:38 字数 488 浏览 3 评论 0原文

下面的代码可以处理我的 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 技术交流群。

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

发布评论

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

评论(1

握住我的手 2024-09-21 07:47:38

您的 RewriteCond 的测试模式有点偏离,但您的想法是正确的:

RewriteCond %{QUERY_STRING} !(\A|&)q=.*

请注意,RewriteCond 仅适用于下一个 RewriteRule,因此,如果您想对所有四个规则执行此排除,则需要复制每个规则上方的 RewriteCond

Your RewriteCond's test pattern is a little off, but you got the right idea:

RewriteCond %{QUERY_STRING} !(\A|&)q=.*

Note that the RewriteCond only applies to the next RewriteRule, so if you want to perform this exclusion for all four of your rules, you'll need to copy the RewriteCond above each of them.

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