简体   繁体   中英

.htaccess file access

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

i have this:

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 realize some files (like js, css) load correctly without using:

RewriteCond %{REQUEST_URI} !-f

will it be better if I add it before my rules, or it doesnt matter?

Usually it is safe to include RewriteCond %{REQUEST_URI} !-f in Rewrite rules so that physical files like css, js, images etc are not affected by these rules.

However in your case none of your rules will impact these css, js, images files because you are not including dot character . in your matching reular expression.

To overcome your issue I recommend using absolute path in your css, js, images files rather than a relative one. Which means you have to make sure path of these files start either with http:// or a slash / .

js, css files will be cached by your browser. But in your case, for the path mentioned in the comments & the rewrites mentioned above. it will not affect. But any future rewrite rules may have affect on these. So it is better to add RewriteCond %{REQUEST_FILENAME} !-f .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM