大网数据广告活动
服务器运维问答

htaccess file with RewriteEngine On causes a 403

· 52CE 我爱测

Windows Server 2022 Apache 2.4.57 x64 httpd.conf - relevant <Directory /> Options none AllowOverride none Require all denied </Directory> DirectoryIndex index.html <Files ".ht*"> Require all denied </Files> httpd-vhosts.conf - re…

问题原文

原帖链接 · MonkeyZeus · CC BY-SA 4.0

Windows Server 2022
Apache 2.4.57 x64

httpd.conf - relevant

<Directory />
    Options none
    AllowOverride none
    Require all denied
</Directory>
DirectoryIndex index.html
<Files ".ht*">
    Require all denied
</Files>

httpd-vhosts.conf - relevant

<VirtualHost *:443>
    DocumentRoot "c:/path/to/public_html"
    DirectoryIndex index.php
    <Directory "c:/path/to/public_html">
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

files

c:/path/to/public_html/index.php
c:/path/to/public_html/.htaccess

.htaccess - full

RewriteEngine Off

When RewriteEngine Off then https://www.example.com/ serves index.php

When RewriteEngine On then https://www.example.com/ results in a 403-Forbidden

Am I missing some obvious directive?

Note: the behavior described above stays the same even if https://www.example.com/index.php is explicitly requested.

已采纳解答

原帖链接 · MonkeyZeus · CC BY-SA 4.0

FIXED!

<VirtualHost *:443>
    DocumentRoot "c:/path/to/public_html"
    
    ## NEW
    RewriteEngine On
    
    DirectoryIndex index.php
    <Directory "c:/path/to/public_html">
        AllowOverride All
        Require all granted
        
        ## NEW
        Options +FollowSymlinks
        
    </Directory>
</VirtualHost>

Checking the logs revealed:

[rewrite:error] AH00670: Options FollowSymLinks and SymLinksIfOwnerMatch are both off, so the RewriteRule directive is also forbidden due to its similar ability to circumvent directory restrictions

RTFM'ing RewriteRule reveals:

To enable the rewrite engine in this context, you need to set "RewriteEngine On" and "Options FollowSymLinks" must be enabled.

Face, meet palm.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2023-06-22)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。