微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

php-Apache Mod Rewrite:带有L参数的RewriteRule.怎么了?

我正在开发一个PHP应用程序,而Apache和Mod Rewrite有一个小问题.有人知道这是怎么回事吗?:

RewriteEngine on
RewriteBase /mysite/
RewriteRule ^css\/css\.css css/css.PHP [L]
RewriteRule ^js\/js\.js js/js.PHP [L]
RewriteRule !^img\/.* index.PHP

当我把http://localhost/css/css.css出现在index.PHP时,也许我缺少了一些东西…
为什么当url与第一个规则apache匹配时,不停止重写过程?

‘last|L’ (last rule)

Stop the rewriting process here and
don’t apply any more rewriting rules.
This corresponds to the Perl last
command or the break command from the
C language. Use this flag to prevent
the currently rewritten URL from being
rewritten further by following rules.
For example, use it to rewrite the
root-path URL (‘/’) to a real one,
e.g., ‘/e/www/’.

自3个小时以来,我已经阅读了论坛和文档,但我仍然遇到同样的问题.

提前致谢.

解决方法:

Centauro12的问题是[L]标志实际上停止了通过以下规则的传播,但随后(如果您在.htaccess文件中)URL映射重新开始.也就是说,您的所有规则都将再次处理.有关详细信息,请参见Apache Rewrite Guide.

因此,您需要显式禁用重写的PHP脚本的重写:

RewriteRule ^css/css.PHP - [L]
RewriteRule ^js/js.PHP - [L]

或更紧凑(尽管可能不是您想要的):

# don't rewrite anything that really exists
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .* - [L]

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐