Htacces Apache END标记替代 [英] Htacces Apache END Flag alternative

查看:62
本文介绍了Htacces Apache END标记替代的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为小型项目编写了一个小型框架(PHP),除已定义的路径外,所有框架都应重定向到index.php?path = $ 1。使用END标志,这没有问题。但是END标志仍然存在,因为Apache 2.3和该脚本也应该在apache 2.2服务器上也可以工作。

I wrote a small framework (PHP) for small projects, which in all should be redirected to index.php?path=$1, except the defined paths. With the END flag this is not problematic. But the END flag exists still since Apache 2.3 and the script should work also on apache 2.2 servers.

有没有人知道如何不用END标志来实现这一点? / p>

Has anyone an idea how I can realize this without the END flag?

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 标志,您或多或少nt完全防止重写引擎的任何循环。要在不使用 END 标志的情况下完成相同的操作,请将其全部替换为 L 标志,并在以下位置添加传递规则开始

Since all of your rules end with the END flag, you more or less want to prevent any looping of the rewrite engine at all. To accomplish the same thing without using the END flag, replace them all with the L flag and add a passthrough rule at the beginning:

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]

这篇关于Htacces Apache END标记替代的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆