【发布时间】:2017-11-19 14:56:44
【问题描述】:
我试图限制可以通过 .htaccess 在目录中访问哪些文件和/或子文件夹。我的问题是,一旦我设置了“全部拒绝”但“允许”访问 index.php,当我简单地输入 site.com/folder 时,我会收到 403 错误,而不是访问 index.php。如何在不弄乱 .htaccess 文件中的规则的情况下恢复默认重定向到索引!?
<Files ~ "^.*">
#Deny Access to Everything
Order Allow,Deny
Deny from all
</Files>
<Files ~ "^index\.php|^changepass\.php|^wr\.php|^wrs\.php|css|js|.*\.png|.*\.jpg|.*\.pdf">
#Allow Exceptions
Order Deny,Allow
Allow from all
</Files>
<Files ~ "^splif\.php">
#Allow Specific Exception
Order Deny,Allow
Allow from all
#Request Authentication
AuthUserFile /home/path/secret/.htpasswd
AuthGroupFile /dev/null
AuthName EnterPassword
AuthType Basic
require user admin
</Files>
【问题讨论】:
-
与其玩 htaccess,不如将所有受保护的文件和文件夹移出 wwwroot?
-
...什么重定向?
-
@Dainis Abols 我会把它移出,但是还有很多其他文件依赖于这些文件。所以限制访问要容易得多!我唯一的选择是手动编写应该阻止哪些文件,但这是不可取的!
-
@Svish 我的意思是当您访问包含它的根文件夹时,网站默认重定向到 index.php!