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]
上一篇:php-RewriteRule htaccess始终删除斜杠偶数目录


下一篇:Nginx Rewrite域名及资源重定向!