【问题标题】:.htaccess can't access my index.htaccess 无法访问我的索引
【发布时间】: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!

标签: php .htaccess redirect


【解决方案1】:

好吧,我的解决方案是在子文件夹中制作一些额外的 .htaccess 文件,仅包含“允许所有命令,拒绝所有命令”,并将文件 ~ “^.*”修改为文件 ~ “php”。这样我就可以阻止所有其他 .php 我不希望人们窥探并留下只能通过名称访问的图像、javascript 和其他格式文件!

【讨论】:

    猜你喜欢
    • 2019-11-11
    • 2022-01-01
    • 2019-09-16
    • 1970-01-01
    • 1970-01-01
    • 2015-04-14
    • 1970-01-01
    • 2023-03-07
    • 1970-01-01
    相关资源
    最近更新 更多