Mehdi Benmoha
Mehdi Benmoha

Reputation: 13

CSS and JavaScript files not loading with mod_rewrite

I'm using an Apache's mod_rewrite with PHP and when I need to add some CSS and JavaScript files, it's not working. I'm using a bootstrap file index.php where all my request are redirected in an htacces I wrote this rule :

RewriteEngine On
RewriteRule (.*) index.php [L]

I think that even the css and js files are redirected to my bootstrap file so I tried to evade them on the rule like this :

RewriteEngine On
RewriteRule (.*[^css,js,less,jpg,jpg,jpeg,png]$) index.php [L]

But the problem is that either my normal request didn't work.

Have you any suggestion to help me solve this problem ?

Upvotes: 1

Views: 1308

Answers (1)

PhearOfRayne
PhearOfRayne

Reputation: 5050

Give this a try it will prevent your files from going through your bootstrap:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ index.php?/$1 [L]

Upvotes: 2

Related Questions