Pim Jager
Pim Jager

Reputation: 32119

RewriteRule redirect

Okay I have this RewriteRule which is supposed to redirect any request for the file base.css to {folder of .htacces file}/include/style/base.css, but is just keeps redirecting in an infinite loop, I thought the L parameter would make sure that wouldn't happen.

RewriteRule (.*)/base.css$ include/style/base.css [L,NC,R=301]

Also it redirects to http://localhost/C:/somemaps/include/style/base.css which it isn't really supposed to do either.

Can anyone tell me how to fix this?
Also I would like to have the RewriteRule so it would redirect any file.css to {folder of .htacces file}/include/style/file.css
BTW the .htacces file is in the root of the website (which is not the root of the server!)

Upvotes: 1

Views: 2436

Answers (3)

Nick Berardi
Nick Berardi

Reputation: 54854

You have Redirect and Rewrite confused. A redirect is a HTTP status code that tells the browser to go to another URL. You actually just want to Rewrite the location to another file location. Try

RewriteRule (.*)/(.*).css$ /include/style/$2.css [L,NC]

If this doesn't work try adding the following right after the RewriteEngine On

RewriteBase /my-virtual-folder-path-where-htaccess-is-stored

Upvotes: 2

Eli
Eli

Reputation: 5610

Also I would like to have the RewriteRule so it would redirect any file.css to {folder of .htacces file}/include/style/file.css

Try this:

RewriteRule ([^/]+).css$ /include/style/$1.css [L,NC]

Upvotes: 2

stesch
stesch

Reputation: 7215

This R=301 makes a new request. Therefor it evaluates the RewriteRule again.

Try to exclude this path/directory with a rewrite condition (RewriteCond).

Upvotes: 1

Related Questions