2013-08-19 11 views
6

小規模なプロジェクト用に小さなフレームワーク(PHP)を作成しました。これは、定義済みのパスを除き、すべてindex.php?path = $ 1にリダイレクトする必要があります。 ENDフラグでは問題ありません。しかし、ENDフラグはApache 2.3以降に存在し、スクリプトはApache 2.2サーバでも動作するはずです。Htacces Apache END Flagの代替方法

私は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] 

答えて

12

あなたのすべてのルールが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]