【问题标题】:.htaccess prevent access from all but root (with or without trailing slash).htaccess 阻止除 root 以外的所有人访问(带或不带斜杠)
【发布时间】:2013-07-16 06:29:40
【问题描述】:

我的方法是 - 除了我熟悉的以外,否认一切。

我想允许访问rootindex.phpfamiliar 'safe' extensions

因此,我不必考虑我应该保护什么,而是考虑我不应该保护什么。

这是我的 .htaccess 文件的外观:

# Disable files and directories index listing
Options -Indexes
DirectoryIndex index.php

# Deny all files.
<FilesMatch ".">
    Order Deny,Allow
    Deny from all
</FilesMatch>

# Except index.php
<FilesMatch "index.php$">
    Order Allow,Deny
    Allow from all
</FilesMatch>

# Except root
<FilesMatch "^$">
    Order Allow,Deny
    Allow from all
</FilesMatch>

# And except familiar extensions
<FilesMatch "\.(css|js|jpe?g|png|gif)$">
    Order Allow,Deny
    Allow from all
</FilesMatch>

一切正常,除非我尝试访问不带斜杠的地址:http://localhost/site 而不是 http://localhost/site/, 然后我得到“禁止”错误页面。

非常感谢一些帮助。

【问题讨论】:

    标签: apache .htaccess


    【解决方案1】:

    回复一个旧帖子,但如果其他人在这里徘徊,您可以按如下方式修改您的 FilesMatch:

    <FilesMatch "^(/)?$">
    

    这匹配位置的根,带或不带斜杠。

    【讨论】:

      【解决方案2】:

      通过仅拒绝对包含点 . 的文件的访问来解决此问题:

      # Deny all files.
      <FilesMatch "\.">
          Order Deny,Allow
          Deny from all
      </FilesMatch>
      

      【讨论】:

        猜你喜欢
        • 2019-01-26
        • 2016-07-14
        • 1970-01-01
        • 1970-01-01
        • 2013-03-10
        • 2016-08-24
        • 2013-08-24
        • 2014-12-22
        • 2013-09-12
        相关资源
        最近更新 更多