Configure mod_rewrite to allow img, js and css files?

in my .htaccess I have the following lines:

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]

I tried to include js files in this line:

<script type="text/javascript" src="system/application/media/js/jquery/jquery.js"></script>

but it does not work, because the rules do not allow it to pass. It works when I turn off the rewrite engine.

how can I change the rules so that it allows the URL using / js, / css and / img?

thank

+3
source share
1 answer

On another RewriteCond after your first, which will prevent the RewriteRule from matching. I sometimes filter specific file extensions for static content files using the following rule:

RewriteCond $1 !\.(js|ico|gif|jpg|png|css|html|swf|mp3|wav|txt)$

If you want to do this based on a directory, then you will need something like this:

RewriteCond $1 !^(css|js|img)/

Put one of them in front of the existing one RewriteCond, and you should be good to go.

+6
source

Source: https://habr.com/ru/post/1741479/


All Articles