8

我为小型项目编写了一个小型框架(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]
4

1 回答 1

15

由于您的所有规则都以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]
于 2013-08-20T00:34:53.107 回答