Reputation: 29
Hello i have a htaccess file who should rewrite all to index.php but except js,css,png files, and this htaccess should load js,css,png files but it doesnt loading it
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/index.html$
RewriteCond %{REQUEST_URI} !\.(gif|jpe?g|png|css|js)$
RewriteRule ^([^/]+)/([^/]+) index.php?checkPage=$1&check=$2 [L,QSA]
RewriteRule ^([^/]+)/? index.php?checkPage=$1 [L,QSA]
Upvotes: 0
Views: 51
Reputation: 45913
RewriteCond
directives only apply to the first RewriteRule
directive. So your second rule has no preceding conditions, so it will naturally rewrite your .js
files as well.
However, you are also checking that the request is not /index.html
, but you are rewriting to index.php
. These should presumably be the same. Although you could probably remove this check altogether by making your regex more specific.
Try the following instead:
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/index\.php$
RewriteCond %{REQUEST_URI} !\.(gif|jpe?g|png|css|js)$
RewriteRule ^([^/]+)/([^/]+) index.php?checkPage=$1&check=$2 [L,QSA]
RewriteCond %{REQUEST_URI} !^/index\.php$
RewriteCond %{REQUEST_URI} !\.(gif|jpe?g|png|css|js)$
RewriteRule ^([^/]+)/? index.php?checkPage=$1 [L,QSA]
However, both theses conditions could probably be removed by simply making your regex more specific, depending on the format of your URLs (which you've not stated).
Upvotes: 1