rewritecond dynamic folder issue

ii silver ii

ǝɹıɟpǝʞɔı&
Dec 18, 2008
767
23
0
Hey,

I have a main.css file buried deep within some folders of a site and I'm trying to use a rewrite rule to change it from this:

example.com/template/dynamicvalue/css/main.css

To

example.com/css/main.css

I'm using the following but It's giving errors so something must be wrong and I can't spot it?

Code:
RewriteCond %{REQUEST_URI} ^template/([a-z]+)/css/main.css
RewriteRule css/main.css$ template/%1/css/main.css [L,QSA]
 


is it actually templates (plural) or was that just an example?

Also, do you have Options +FollowSymlinks set?
 
If this were a php script, using say smarty and such, you would usually have the template path configured and stashed into a variable so that in the html code you would have something like:

<script src="{$template_root}/file.js"...></script>
<link rel="Stylesheet" href="{$template_root}/css/main.css"/>

But if I had to guess on the error, I would say is because you have an incorrect regex expression for the rewrite rule.

RewriteRule ^css/main.css$ template/path-furth-down/css/main.css

The problem with your combination of both RewriteCond and RewriteRule however is that they are conflictive. If the user entered /css/main.css in their browser, or it was included in the HTML source, then the REQUEST_URI and Filename is going to be /css/main.css, as a result would never match what you're trying to do.

If it were the Nginx webserver, and I knew the path of the template folder, I would have done something like this for the css portion:

Code:
location ~ ^/css/(.*)$ {
  alias /template/somevalue/css/$1;
}