RewriteCond不明白怎么申请!

发布于 2024-10-09 22:11:44 字数 190 浏览 0 评论 0原文

RewriteRule ^articles/([0-9]+)-(.*)\.html$ article.php?id=$1 [L]
RewriteRule .* index.php

由于 .htaccess 中的 [L] 问题,我仍然不明白如何应用 RewriteCond 帮助!并提前致谢:)

I have this

RewriteRule ^articles/([0-9]+)-(.*)\.html$ article.php?id=$1 [L]
RewriteRule .* index.php

I still don't understand how to apply RewriteCond, due to [L] issues in .htaccess. Help!and thanks in advance :)

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

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

发布评论

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

评论(2

ぃ弥猫深巷。 2024-10-16 22:11:44

关于 serverfault 有一个很好的参考问题,它解释了规则和条件如何相互作用:
您的一切曾经想了解 Mod_Rewrite 规则但又不敢问吗?

按照 Meta 当前讨论建议的链接。

There is an excellent reference question on serverfault, which explains how rules and conditions interact:
Everything You Ever Wanted to Know about Mod_Rewrite Rules but Were Afraid to Ask?

Link as advised by current discussion on Meta.

迷雾森÷林ヴ 2024-10-16 22:11:44

我猜您正在寻找类似的内容:

RewriteRule ^articles/([0-9]+)-(.*)\.html$ article.php?id=$1 [L]
RewriteCond $0 !=article.php
RewriteRule .* index.php

另一个解决方案是使用第二个 RewriteRule 的模式排除 article.php

RewriteRule !^article\.php$ index.php

但请注意,这将重写 任何其他请求(包括其他现有文件)。为了解决这个问题,您可以对第二条规则使用不同的条件:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* index.php

I guess you’re looking for something like this:

RewriteRule ^articles/([0-9]+)-(.*)\.html$ article.php?id=$1 [L]
RewriteCond $0 !=article.php
RewriteRule .* index.php

Another solution would be to exclude article.php with the pattern of the second RewriteRule:

RewriteRule !^article\.php$ index.php

But note that this will rewrite any other request (including other existing files). To conquer that you could use a different condition for the second rule:

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