1

I actually thought there should already be a thread about this but i wasn't able to find one.

let's say i have a website with this structure:

/index.php
/.htaccess
/template
/template/css
/template/css/foo.css

I'm redirecting everything to index.php with .htaccess

RewriteEngine on
RewriteBase /
RewriteRule ^(.*)$ index.php?0=$1 [QSA,L]

Now I've got a problem with the css. that i could fix by placing another .htaccess in /template with this

RewriteEngine off
Options -Indexes

And then access the css file with http://example.com/template/css/foo.css but actually i would prefere to have just http://example.com/css/foo.css

So i tried to put in /.htaccess the following code (that didn't worked). What did i do wrong?

RewriteEngine on
RewriteBase /
RewriteRule ^/css/(.*) www/css/$1 [L]
RewriteRule ^/js/(.*) www/js/$1 [L]
RewriteRule ^(.*)$ index.php?0=$1 [QSA,L]

note I don't have any .htaccess in /template!

1 Answer 1

1

You should remove the htaccess file in the css folder. You just need to exclude rewrites to the template directory. You can do it all in a single file:

RewriteEngine on
RewriteBase /

RewriteCond %{DOCUMENT_ROOT}/template/%{REQUEST_URI} -f
RewriteRule ^(.*)$ /template/$1 [L]

RewriteCond ${REQUEST_URI} ^/template/
RewriteRule ^(.*)$ index.php?0=$1 [QSA,L]

The first rule handles requests for the css directory, and the second rule is the one you had that routes to index.php except if the request is for template.

Sign up to request clarification or add additional context in comments.

1 Comment

Hi first of all thank you (: I'm not sure if it's correct to respond here but I don't see where else. so now i have index.php .htaccess www/ www/css/ www/css/test.css www/img/ www/js/ www/js/test.js in .htaccess i have this: RewriteEngine on RewriteBase / RewriteCond %{DOCUMENT_ROOT}/css/%{REQUEST_URI} -f RewriteRule ^(.*)$ /www/css/$1 [L] RewriteCond %{DOCUMENT_ROOT}/js/%{REQUEST_URI} -f RewriteRule ^(.*)$ /www/js/$1 [L] RewriteCond %{DOCUMENT_ROOT}/img/%{REQUEST_URI} -f RewriteRule ^(.*)$ /www/img/$1 [L] RewriteRule ^(.*)$ index.php?0=$1 [QSA,L] What's wrong?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.