user2698024
user2698024

Reputation:

Htacces Apache END Flag alternative

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.

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]

Upvotes: 8

Views: 4154

Answers (1)

Jon Lin
Jon Lin

Reputation: 143906

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]

Upvotes: 15

Related Questions