我为小型项目编写了一个小型框架(PHP),除已定义的路径外,所有这些框架都应重定向到index.php?path = $ 1。使用END标志,这没有问题。但是END标志仍然存在,因为Apache 2.3和该脚本也应在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]

最佳答案

由于所有规则都以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]

关于apache - Htaccess Apache END标记替代,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/18324233/

10-13 02:48