Htaccess Apache END Flag替代方案

时间:2013-08-19 22:37:32

标签: apache .htaccess

我为小项目编写了一个小框架(PHP),除了定义的路径外,它们应该全部重定向到index.php?path = $ 1。使用END标志这不是问题。但是自从Apache 2.3以来,END标志仍然存在,脚本也应该在apache 2.2服务器上运行。

有没有人知道如何在没有END标志的情况下实现这个目标?

RewriteEngine on

# Define static redicts
RewriteRule ^image/(.+)$ public/image/$1 [END,QSA]
RewriteRule ^css/(.+)$ public/css/$1 [END,QSA]
RewriteRule ^js/(.+)$ public/js/$1 [END,QSA]
RewriteRule ^lib/js/core/(.+)$ core/lib/js/$1 [END,QSA]
RewriteRule ^lib/js/(.+)$ public/lib/js/$1 [END,QSA]
RewriteRule ^cache/(.+)$ public/cache/$1 [END,QSA]
RewriteRule ^download/(.+)$ public/download/$1 [END,QSA]

# Define custom redicts
RewriteRule ^page/([0-9]+)$ index.php?path=index.php&page=$1 [END,QSA]

# Define all other redicts
RewriteRule ^(.+)$ index.php?path=$1 [L,QSA]

1 个答案:

答案 0 :(得分:14)

由于您的所有规则都以END标志结束,因此您或多或少想要阻止任何重写引擎的循环。要在不使用END标志的情况下完成相同的操作,请使用L标记替换它们,并在开头添加直通规则:

RewriteEngine on

# pass-through if another rewrite rule has been applied already
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule ^ - [L]

# Define static redicts
RewriteRule ^image/(.+)$ public/image/$1 [L,QSA]
RewriteRule ^css/(.+)$ public/css/$1 [L,QSA]
RewriteRule ^js/(.+)$ public/js/$1 [L,QSA]
RewriteRule ^lib/js/core/(.+)$ core/lib/js/$1 [L,QSA]
RewriteRule ^lib/js/(.+)$ public/lib/js/$1 [L,QSA]
RewriteRule ^cache/(.+)$ public/cache/$1 [L,QSA]
RewriteRule ^download/(.+)$ public/download/$1 [L,QSA]

# Define custom redicts
RewriteRule ^page/([0-9]+)$ index.php?path=index.php&page=$1 [L,QSA]

# Define all other redicts
RewriteRule ^(.+)$ index.php?path=$1 [L,QSA]