weexpectedTHIS
weexpectedTHIS

Reputation: 3376

How to make my htaccess file rewrite all traffic to cgi-bin

I want to make my htaccess file redirect all traffic except that to /images, /css, and /javascripts to the cgi-bin.

RewriteEngine on
RewriteCond %{REQUEST_URI} !^images/.*$
RewriteCond %{REQUEST_URI} !^css/.*$
RewriteCond %{REQUEST_URI} !^javascript/.*$
RewriteCond %{REQUEST_URI} !^cgi-bin/.*$
RewriteRule (.*) /cgi-bin/$1 [L]

I want a request for: example.com/index to retrieve example.com/cgi-bin/index
but I also want a request for: example.com/images/foo.png to retrieve example.com/images/foo.png

What is wrong with my file? I keep getting this error: Request exceeded the limit of 10 internal redirects due to probable configuration error.

Upvotes: 0

Views: 1796

Answers (1)

Ulrich Palha
Ulrich Palha

Reputation: 9509

You are missing the leading / in all of your RewriteConds, which are required, though they should not be used for RewriteRule in .htaccess, which does cause confusion.

RewriteEngine on
RewriteCond %{REQUEST_URI} !^/images/ [NC]
RewriteCond %{REQUEST_URI} !^/css/ [NC]
RewriteCond %{REQUEST_URI} !^/javascript/ [NC]
RewriteCond %{REQUEST_URI} !^/cgi-bin/ [NC]
RewriteRule (.*) /cgi-bin/$1 [L]

You also don't need the .*$ so I removed them to make it more efficient.

Upvotes: 1

Related Questions