[英]Custom Error page isn't loading when URL contains "/ /"
I'm having a very specific issue with a site I'm building that is set up to use friendly URLs and custom error pages.我正在构建的网站存在一个非常具体的问题,该网站设置为使用友好的 URL 和自定义错误页面。 I've been reading the message boards for days and although there are a lot of similar seeming posts, nothing addresses this problem specifically... at least to my newbie eyes.
几天来我一直在阅读留言板,虽然有很多类似的帖子,但没有什么专门解决这个问题......至少在我的新手眼中。
Mostly everything on my site is running ok:我网站上的大部分内容都运行正常:
Where I'm running into trouble is if the URL gets corrupted to contain a single space followed by a forward slash:我遇到麻烦的地方是 URL 是否被损坏以包含一个空格,后跟一个正斜杠:
When this happens a 403 error gets triggered but it doesn't load the custom 403.php page.发生这种情况时会触发 403 错误,但不会加载自定义 403.php 页面。
Noteably, this problem does not occur if the URL lacks the trailing slash:值得注意的是,如果 URL 缺少尾部斜杠,则不会出现此问题:
These all trigger 404 errors rather than 403, which is what I would like to happen when the trailing slash is included.这些都触发 404 错误而不是 403,这是我希望在包含斜杠时发生的情况。
I realize this is a very specific situation that will only occur if someone mangles a url while they're typing it in, but I would love for it to not happen.我意识到这是一种非常特殊的情况,只有当有人在输入 url 时才会发生这种情况,但我希望它不会发生。 I talked with my web host and they said everything is correct on their end.
我与我的 web 主机交谈,他们说一切都是正确的。
Here's the code I'm currently running in .htaccess in my /public-html/ directory:这是我当前在 /public-html/ 目录中的 .htaccess 中运行的代码:
ErrorDocument 403 https://www.example.com/403.php
# Begin EnforceSSL
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L]
</IfModule>
# End EnforceSSL
RewriteEngine On
RewriteBase /
# The Friendly URLs part
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [L,QSA,NC]
and here's the code in index.php which handles the friendly URLs:这是 index.php 中处理友好 URL 的代码:
<?php
// Create a URL array containing any passed variables, including requested page
$URL = explode("/", $_SERVER[QUERY_STRING]);
// Load the page
if (trim($URL[0]) == "index"){
require_once("home.php");
} else if (trim(($URL[0]) == "")){
require_once("home.php");
} else if (file_exists(strtolower(trim($URL[0])).".php")) {
require_once(strtolower(trim($URL[0])).".php");
} else {
require_once("404.php");
}
?>
Any help is greatly appreciated!任何帮助是极大的赞赏!
it's just a default Apache response: "403 Forbidden Forbidden You don't have permission to access / / on this server."
它只是一个默认的 Apache 响应:“403 Forbidden Forbidden 您无权访问此服务器//。”
There is likely a rule (mod_security perhaps) that is defined in the server config that is blocking such requests.在阻止此类请求的服务器配置中可能定义了一条规则(可能是 mod_security)。 The issue here is that the
ErrorDocument
defined in .htaccess
is too late to serve your custom response.这里的问题是
.htaccess
中定义的ErrorDocument
为时已晚,无法为您的自定义响应提供服务。 You would need to define the ErrorDocument
earlier in the server config.您需要在服务器配置中更早地定义
ErrorDocument
。
If you are on a shared server then you will need to contact your host to debug this further.如果您在共享服务器上,则需要联系您的主机以进一步调试。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.