【问题标题】:Deny all exept one folder and one file with htaccess [duplicate]使用htaccess拒绝除一个文件夹和一个文件之外的所有文件[重复]
【发布时间】:2014-05-20 16:36:18
【问题描述】:

我的项目结构是:

-application
-lib
-public
-index.php
-.htaccess

.htaccess 现在是:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]

我需要限制对除 publicindex.php 文件之外的所有文件夹的访问。怎么做?

我尝试将Deny all 添加到我的.htaccessAllow allpublic 文件夹中,但是我的index.php 变得无法访问。

【问题讨论】:

    标签: php apache .htaccess


    【解决方案1】:

    不要使用RewriteRule。请改用以下内容:

    Order Deny,Allow
    Deny from all
    Allow from 127.0.0.1
    
    <Files /index.php>
        Order Allow,Deny
        Allow from all
    </Files>
    
    <Directory "/public">
        Allow from all
    </Directory>
    

    【讨论】:

    • 这是你自己写的吗?
    • 改编自两个网站,甚至有一些网站可以轻松生成
    • @Xavjer 但我的 index.php 是FrontController,所以所有请求都应该重定向到那里。如何保存这种行为?
    • 好的,那是另一种情况,检查premium.wpmudev.org/forums/topic/… 将其适应您的公用文件夹,它应该可以工作
    猜你喜欢
    • 2014-01-08
    • 2011-03-25
    • 2013-10-03
    • 1970-01-01
    • 1970-01-01
    • 2013-07-25
    • 1970-01-01
    • 2015-05-10
    • 1970-01-01
    相关资源
    最近更新 更多