Anders
Anders

Reputation: 217

.htaccess on specific filetypes

I have some magic stuff in my htaccess. It works very well but I don't know how

RewriteRule ^[^_+/]. index.php

I think it says that all requests should go through index.php no matter which directory the visitor ask for. So far so good. However images, css files, js files etc should of course not be parsed in index.php. Can I exclude certain directories from the above rule? Like /img, /css and /js

Other suggestions?

Thanks in advance

Upvotes: 0

Views: 222

Answers (2)

Peter O'Callaghan
Peter O'Callaghan

Reputation: 6186

You can avoid requests to certain paths by using a simple RewriteCond...

RewriteCond ${REQUEST_URI} !^css
RewriteCond %{REQUEST_URI} !^img
RewriteCond %{REQUEST_URI} !^js
# or alternatively just
RewriteCond ${REQUEST_URI} !^(css|img|js)

Upvotes: 1

Your Common Sense
Your Common Sense

Reputation: 157864

you can exclude existing files and directories

RewriteCond  %{REQUEST_FILENAME} !-f
RewriteCond  %{REQUEST_FILENAME} !-d

by placing this before your rule

Upvotes: 4

Related Questions