.htaccess file access

I have a question regarding access to .htaccess file for css and js files

I have it:

RewriteEngine On RewriteBase / RewriteRule ^$ index.php?page=index [L,NC] RewriteRule ^([a-z0-9]+)/?$ index.php?page=$1 [L,NC] RewriteRule ^([a-z0-9]+)/([a-z0-9]+)/?$ index.php?page=$1&subpage=$2 [L,NC] 

Now I understand that some files (e.g. js, css) load correctly without using:

 RewriteCond %{REQUEST_URI} !-f 

would it be better if I add it before my rules, or does it not matter?

+4
source share
2 answers

It is generally safe to include RewriteCond %{REQUEST_URI} !-f in rewrite rules so that these physical rules do not affect physical files such as css, js, images, etc.

However, in your case, none of your rules will affect these css, js, images files because you do not include the dot character . in the corresponding reular expression.

To overcome your problem, I recommend using the absolute path in your css, js, image files , and not in the relative. This means that you must make sure that the path to these files starts with http:// or a slash / .

+5
source

js, css files will be cached by your browser. But in your case, for the path mentioned in the comments and censuses mentioned above. it will not affect. But any rewriting rules can affect them. Therefore, it is better to add RewriteCond %{REQUEST_FILENAME} !-f .

0
source

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


All Articles