Redirecting RewriteRule

Ok I have this RewriteRule which should redirect any request for the base.css file to the {.htacces file} /include/style/base.css folder but just keeps the redirect in an infinite loop, I thought the L parameter would guarantee this will not 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 shouldn't do either.

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

+1


source to share


3 answers


You have redirection and messed up. A redirect is an HTTP status code that tells the browser to navigate to a different URL. You just want to overwrite the location to a different file location. Try

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

      



If that doesn't work, try adding the following right after turning RewriteEngine On

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

      

+2


source


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

Try the following:



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

      

+2


source


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

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

+1


source







All Articles