views:

760

answers:

3

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!)

+2  A: 

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
Nick Berardi
mm, doesn't work.
Pim Jager
You are going to have to be more specific, about what is not working. You may have to use RewriteBase to get the correct path to the /include/style file.
Nick Berardi
Thanks, both you and Eli really helped!
Pim Jager
+1  A: 

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

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

stesch
I don't think he was trying to do a redirect, because it wouldn't make any sense to redirect a style sheet file. I think he just wanted a plain old physical file path rewrite.
Nick Berardi
+2  A: 

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]
Eli
thank you very much.
Pim Jager
And note that you're *rewriting* the URL (chaning how Apache processes), not *redirecting* it (telling the browser it has moved). That's a crucial difference in understanding mod_rewrite.
Eli