我有用于PHP的Apache2.4 Web服务器,我想使用.htaccess确保它的安全,这样除了根文件夹(var/www/html/index.php)中的index.php以外,没有人能够访问我的文件.问题是,在我的配置中,它只允许从localhost/index.php开始的index.php,而不是localhost/.我try 重定向,但没有太大变化:

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>

推荐答案

正在改变

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

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

解决了这个问题;

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

  • ~表示正则表达式
  • then we are searching for index.php or empty string (which is root direc至ry in this case)

Php相关问答推荐

提交表格后的重定向不起作用

在不刷新页面的情况下无法使用JQuery更新id

Laravel—通过单击处理多条路由

产品ACF值在WooCommerce我的账户订单的附加列中为空

FatFreeFramework上的不同路由

WooCommerce/WordPress:简单的产品属性显示

将购买限制在WooCommerce中具有相同产品属性的项目

在Symfony 6.4中将工作流动态添加到服务

未检测到laravel控制器

在 WooCommerce 更新结帐事件上动态更新自定义内容

将自定义保存金额移至 Woocommerce 简单产品中的价格以下

Google Drive API:为什么使用服务帐户在下载文件时会将我带到 Google Drive 登录窗口?

Laravel 发送邮箱问题 Swift_TransportException

CodeIgniter 4中嵌套过滤器组不起作用

.htaccess环境变量条件不被判断

MySQLI bind_param导致的Cannot modify readonly property错误

从 laravel 中的日期类型中删除时间

将样式文件或脚本引入WordPress模板

为什么可以从 PHP 类访问 PHP Trait 的私有成员?

如何将 2021-04-08T22:25:09.335541Z 作为时间戳保存到 Laravel 中的数据库中?