fnkr
fnkr

Reputation: 10075

htaccess RewriteRule without RewriteCond not working

Why does this work:

Options +ExecCGI
AddHandler fcgid-script .fcgi
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /app.fcgi/$1 [L]

But if I remote the RewriteCond it doesnt work and I get an internal server error.

Options +ExecCGI
AddHandler fcgid-script .fcgi
RewriteEngine On
RewriteRule ^(.*)$ /app.fcgi/$1 [L]

If I modify the RewriteCond e.g. like this it doesnt work too.

RewriteCond %{REQUEST_FILENAME} !-l

I want to redirect all requests to app.fcgi. I dont want the user to be able to access files directly.

Thanks in advance!

Upvotes: 4

Views: 4365

Answers (1)

anubhava
anubhava

Reputation: 785856

It is giving you internal server error (500) because without RewriteCond your loop is infinitely looping.

You can use this rule to prevent this:

Options +ExecCGI
AddHandler fcgid-script .fcgi
RewriteEngine On
RewriteRule ^((?!app\.fcgi/).*)$ /app.fcgi/$1 [L,NC]

(?!app\.fcgi/) is a negative lookahead that prevents this rewrite rule to execute if request is already /app.fcgi/.

Upvotes: 5

Related Questions