gea*_*tal 7 apache .htaccess http-status-code-403
如果我DirectorySlash Off
在我的.htaccess
文件中设置并调用没有尾部斜杠的目录403-Forbidden
,我从我的服务器获取.如果我用斜线调用它一切正常.
谁有人解释为什么?这是我完全匿名的.htaccess
:
# GLOBAL CONFIG
Options +FollowSymlinks
DirectorySlash Off
AddDefaultCharset utf-8
php_value post_max_size 256M
php_value upload_max_filesize 256M
# BEGIN WordPress
RewriteEngine On
RewriteBase /folder/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /folder/index.php [L]
# END WordPress
# REMOVE WWW
RewriteCond %{HTTP_HOST} ^([^.]+)\.domain\.com$ [NC]
RewriteRule ^(.*)$ http://domain.com$1 [R=301,L]
Run Code Online (Sandbox Code Playgroud)
Tim*_*one 13
正如您所知,根据文档,何时DirectorySlash
设置为Off
,请求/folder
未进行DirectoryIndex
评估.这意味着请求不会自动映射到/folder/index.php
.
mod_dir
在请求处理的"fixup"阶段执行此检查.mod_rewrite
,负责您的RewriteRule
定义,当您在.htaccess
文件中指定规则时,也会在此阶段执行处理 .
但是,它是通过对模块的识别来编程的mod_dir
,并且包括检查以确保使用尾部斜杠请求当前目录.如果没有,它拒绝处理请求,因为这样做可能会导致未定义的行为.
然后,请求转到内容生成阶段,由于请求未映射到真实文件,因此处理该阶段mod_autoindex
.如果Indexes
默认情况下在您的主机上禁用,则mod_autoindex
返回403 Forbidden
您看到的内容.
请注意,由于DirectoryIndex
不计算,即使mod_rewrite
是处理请求时,它仍然会失败,因为没有自动分辨率index.php
会发生,您的规则
RewriteRule . /folder/index.php [L]
Run Code Online (Sandbox Code Playgroud)
不匹配,因为.
需要匹配的东西(但请求将是空白的).
启用DirectorySlash
可以通过纠正除了最后一个注释之外的所有前面提到的方案中的阻止操作来防止这种情况,最后一个注释由DirectoryIndex
请求映射的事实来处理index.php
.
小智 8
使用Apache 2.4,您可以通过设置允许重写.htaccess文件RewriteOptions AllowNoSlash
.
Changes with Apache 2.3.16
...
*) mod_rewrite: Add the AllowNoSlash RewriteOption, which makes it possible
for RewriteRules to be placed in .htaccess files that match the directory
with no trailing slash. PR 48304.
[Matthew Byng-Maddick <matthew byng-maddick bbc.co.uk>]
...
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
12138 次 |
最近记录: |