duandan9680
2017-01-14 09:06
浏览 116
已采纳

仅允许通过代码使用.htaccess访问文件夹

I want to hide my uploads folder but i want to access it via php . Is this possible with .htaccess ? I tried something but didn't worked.

    <files "/uploads">
  order allow,deny
  deny from all
    </files>

    <folders uploads>
Order Allow,Deny
Deny from all
    </folders>

图片转代码服务由CSDN问答提供 功能建议

我想隐藏我的 uploads 文件夹,但我想通过php访问它。 是否可以使用 .htaccess ? 我尝试了一些但没有用的。

 &lt; files“/ uploads”&gt; 
 order allow,deny 
 deny from all 
&lt; / files&gt; 
 
&lt; folders uploads&gt;  
订单允许,拒绝
Deny来自所有
&lt; / folders&gt; 
   
 
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • drgmszo076956 2017-01-14 09:19
    已采纳

    You're almost there, but it depends on what version of Apache you're using also.

    The above method you're trying is if you want to block access to a specific file, if you want to block a folder, then add your .htaccess file to that folder and just use:

    Below 2.4:

    deny from all
    

    2.4 or above:

    Require all denied
    
    打赏 评论
  • dqdes60666 2017-01-14 09:20

    IMPORTANT EDIT

    You can just upload a .htaccess to the folder that you want to block with the following:

    Deny from all
    

    If there is some issue, add:

    Allow from 127.0.0.1
    

    It worked well for me.

    Original answer

    Try:

    <Directory "/uploads">
        Order allow,deny
        Deny from all
        Allow from 127.0.0.1
    </Directory>
    

    EDIT:

    The code above will deny all except the local ip (of your server).

    As thickguru said, it also depends on your apache version. Here are some other ways to do it:

    <Directory "/uploads">
        Require local
    </Directory>
    

    It will only allow if requested by the server (your script or somewhat on the server).

    Or:

    <Directory "/uploads">
        Require ip 127.0.0.1
    </Directory>
    

    The same as above, but using the local adress. You can also add other ips to it. All the ips that you add there will be allowed to access the folder.

    打赏 评论

相关推荐 更多相似问题