【发布时间】:2015-08-07 10:05:10
【问题描述】:
我正在使用
RewriteEngine On
RewriteRule ^.*$ ./index.php
通过 index.php 重定向我的所有网站流量,并让我的 php 代码获取 request_uri 并相应地路由每个请求。
我想限制对所有其他文件/目录的访问,除了包含 js 文件、css 文件、图像等的文件/目录。
我发现我可以这样做:
Order deny,allow
Deny from all
<Files index.php>
Order Allow,Deny
Allow from all
</Files>
然后在公共目录中添加另一个 .htaccess 文件以允许某些文件类型。
当我导航到 localhost/mysite/index.php 时,它工作正常,因为 index.php 文件是可访问的。
但是对于任何其他 url,我得到一个 403,例如 /mysite/home/ 是被禁止的,即使我希望它可以正常工作。
我能做些什么来获得预期的行为?
我的完整 .htacces 文件是:
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^.*$ ./index.php
Order deny,allow
Deny from all
<Files index.php>
Order Allow,Deny
Allow from all
</Files>
编辑:/public/.htaccess 目前看起来像这样:
<Files ~ "\.(xml|css|jpe?g|png|gif|js|pdf)$">
Allow from all
</Files>
【问题讨论】:
-
你也可以显示
/public/.htaccess吗? -
@anubhava 我编辑了问题以包含它。
标签: php regex apache .htaccess mod-rewrite