简体   繁体   English

.htaccess文件访问

[英].htaccess file access

i have a question regarding .htaccess file access for css files and js files 我有一个关于css文件和js文件的.htaccess文件访问的问题

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: 现在,我意识到一些文件(如js,css)正确加载而不使用:

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. 通常在Rewrite规则中包含RewriteCond %{REQUEST_URI} !-f是安全的,这样物理文件如css,js,images等不受这些规则的影响。

However in your case none of your rules will impact these css, js, images files because you are not including dot character . 但是在您的情况下,您的规则都不会影响这些css,js,图像文件,因为您不包括点字符. in your matching reular expression. 在你的匹配reular表达式中。

To overcome your issue I recommend using absolute path in your css, js, images files rather than a relative one. 为了解决您的问题,我建议您在css,js,images文件中使用绝对路径而不是相对路径 Which means you have to make sure path of these files start either with http:// or a slash / . 这意味着您必须确保这些文件的路径以http://或斜杠/开头。

js, css files will be cached by your browser. js, css文件将由您的浏览器缓存。 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 . 所以最好添加RewriteCond %{REQUEST_FILENAME} !-f

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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