htaccess重写规则麻烦

发布于 2024-10-04 17:36:11 字数 614 浏览 0 评论 0原文

我无法让我的重写规则正常工作。.

ErrorDocument 404 /404.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^companies/
RewriteRule ^companies\/\?(.*)([A-Za-z]+) index.php?cpy=$1 [R=301,L,NC] 

RewriteRule ^([0-9]+)/?$ index.php?cid=$1 [L]
RewriteRule ^([A-Za-z_]+)/?$ index.php?cat=$1 [L]

重写规则 域名.com/123 域名.com/abc 似乎工作正常,

但我无法上班的另一件事是 domain.com/companies/?list=this

似乎 apache 找不到匹配项

RewriteRule ^companies\/\?(.*)([A-Za-z]+) index.php?cpy=$1 [R=301,L,NC] 

谁能帮我找出该规则有什么问题吗?或者如果是别的什么?

I am having troubles getting my rewrite rules to work correctly..

ErrorDocument 404 /404.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^companies/
RewriteRule ^companies\/\?(.*)([A-Za-z]+) index.php?cpy=$1 [R=301,L,NC] 

RewriteRule ^([0-9]+)/?$ index.php?cid=$1 [L]
RewriteRule ^([A-Za-z_]+)/?$ index.php?cat=$1 [L]

The rewrite rules for
domain.com/123
domain.com/abc
seem to work ok,

but the other one I cannot get to work is
domain.com/companies/?list=this

It seems that apache doesn't find a match for

RewriteRule ^companies\/\?(.*)([A-Za-z]+) index.php?cpy=$1 [R=301,L,NC] 

Can anyone help me figure out what is wrong with that rule? or if it is something else?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

红颜悴 2024-10-11 17:36:11

RewriteRule 通常与查询字符串不匹配。

您可以使用 RewriteCond 对它们进行匹配,参数化匹配显示为 %1、%2 等,例如

RewriteCond %{QUERY_STRING} ^(.*)([A-Za-z]+)$
RewriteRule ^companies\/ index.php?cpy=%1 [R=301,L,NC]

RewriteRules do not match on query strings as a rule.

You can match on them using RewriteCond with the parameterized matches appearing as %1, %2, etc.

eg.

RewriteCond %{QUERY_STRING} ^(.*)([A-Za-z]+)$
RewriteRule ^companies\/ index.php?cpy=%1 [R=301,L,NC]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文