【问题标题】:.htaccess RewriteEngine causing Unexpected 403 Forbidden http response code in xampp.htaccess RewriteEngine 在 xampp 中导致 Unexpected 403 Forbidden http 响应代码
【发布时间】:2021-10-10 00:50:52
【问题描述】:

我正在使用 xampp 测试一些 php 代码。

在主项目目录中,我有以下 .htaccess 文件:

RewriteEngine on

#Index
RewriteCond %{REQUEST_FILENAME} ^/$  
RewriteRule request_handler.php [L]

#php files
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f [OR]
RewriteCond %{REQUEST_FILENAME} ^.*(\.php)$
RewriteRule . request_handler.php [L]

#Blocked files. PHP blocked files should be specified in request_handler.php
<Files "setup.json">
    Order Allow,Deny
    Deny from all
</Files>
<Files "testimonials.json">
    Order Allow,Deny
    Deny from all
</Files>

#CACHE CONTROLL FOR STATIC RESOURSES
<FilesMatch "\.(jpg|jpeg|png|gif|swf)$">
    Header set Cache-Control "max-age=2592000, public"
</FilesMatch>

无论如何,我在所有请求中都遇到了意外的 403 禁止。但是,如果我删除 .htaccess 文件的第一行,我将不再出现这种意外行为。

有谁知道是什么导致了这个错误?

更新 我创建了一个新的 .htaccess 文件,它只包含一行:RewriteEngine On,但我仍然收到错误消息。 (如果我删除该行,我将停止收到错误)。该行的唯一存在会导致错误。

【问题讨论】:

    标签: php apache .htaccess xampp http-status-code-403


    【解决方案1】:

    事实证明,我所要做的就是在 RewriteEngine On 指令之前添加行 Options FollowSymLinks

    这是 Apache 不得不说的:

    要在此上下文中启用重写引擎,您需要设置“RewriteEngine On”并且必须启用“Options FollowSymLinks”。 [...] 出于安全原因,需要此限制。

    Apache documentation

    【讨论】:

      猜你喜欢
      • 2012-04-21
      • 2011-03-18
      • 2015-07-17
      • 2015-07-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-03
      • 1970-01-01
      相关资源
      最近更新 更多