Htaccess只允许查看JS和CSS文件?

时间:2014-12-20 15:00:56

标签: .htaccess mod-rewrite

我想有一个htaccess规则,只限于允许查看js和CSS文件。

我会为/ paymethod /.

中的所有内容执行此操作

所以这应该是可见的:

/paymethod/css/css.css
/paymethod/js/test.js

但不是这个

/paymethod/js/data.php
/paymethod/else/data.php
/paymethod/else/data.html

(那些应该只在服务器端工作,但不应该访问它们)

由于我的Kohana框架已经有了这个:

RewriteRule ^(?:application|modules|system)\b.* index.php/$0 [L]

我添加了| paymethod,就像这样:

RewriteRule ^(?:application|modules|system|paymethod)\b.* index.php/$0 [L]

它有效,但这只限制了包括css和js文件在内的所有内容。

我该怎么做?

1 个答案:

答案 0 :(得分:2)

您可以在.htaccess目录中使用此paymethod/

RewriteEngine on 
RewriteCond %{REQUEST_URI} !\.(?:css|js)$ [NC]
RewriteRule ^ - [L,F] 

或在根.htaccess中:

RewriteCond %{REQUEST_URI} !\.(?:css|js)$ [NC]
RewriteRule ^paymethod/ - [L,F]