Apache 只允许index.php - 不能从根目录工作

问题描述 投票:0回答:1

我有适用于 PHP 的 Apache 2.4 Web 服务器,我想使用 .htaccess 使其安全,这样除了根文件夹 (

index.php
) 中的
var/www/html/index.php
之外,没有人能够访问我的文件。问题是,根据我的配置,它仅允许来自
localhost/index.php
而不是
localhost/
的 index.php。我尝试过重定向,但没有太大变化:

DirectoryIndex index.php

# Redirect the root (/) to index.php
RewriteEngine On
RewriteRule ^$ /index.php [L]

# Deny all requests by default
Require all denied

# Allow only access to index.php
<Files "index.php">
  Require all granted
</Files>
php apache .htaccess security
1个回答
0
投票

改变

<Files "index.php">
  Require all granted
</Files>

<Files ~ "^(index\.php|)$">
  Require all granted
</Files>

解决了问题;

<Files ~ "^(index\.php|)$">

  • ~
    表示正则表达式
  • 然后我们正在搜索
    index.php
    或空字符串(在本例中是根目录)
© www.soinside.com 2019 - 2024. All rights reserved.