gpt4 book ai didi

apache - htaccess 文件拒绝所有,重定向到 404 在 403.shtml 上找不到,但未定义自定义错误页面

转载 作者:行者123 更新时间:2023-12-02 17:49:56 24 4
gpt4 key购买 nike

我正在 cPanel 的新插件域中设置一个快速内部项目。这个特定的安装了 SSL 证书。我正在构建我的 .htaccess 并添加了 <Files config.php>指令deny from all这样我的 config.php 文件就无法访问。我意识到将其存储在网络根目录之外是理想的选择,但在这种情况下我不能。

通常我会期望当去 www.domain.com/config.php 时在浏览器中我会得到 Apache 的默认 403 Forbidden 页面。这是同一服务器上的其他域上发生的情况。但在这种情况下,我收到 404 未找到错误,指出:

Not Found
The requested URL /403.shtml was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

如果我试图定义自定义错误文档,我通常会期望这一点,但在这种情况下,我不会!
使该域与同一 cPanel 帐户中的所有其他域不同的唯一原因是它具有 SSL 证书。无论使用 http 还是 https 进行导航,这个 404 错误都是相同的。我已经尝试清除缓存,但还是一样。

任何人都可以看到下面我的 .htaccess 中可能导致此问题的任何内容吗?

DirectoryIndex /index.php

Options -Indexes +FollowSymLinks
ServerSignature Off

# PARSE PHP IN OTHER FILES
# AddType FOR PHP AS APACHE MODULE, AddHandler FOR CGI
AddType application/x-httpd-php .ics .xml

# ATTEMPT FORCE PDF DOWNLOAD
AddType application/octet-stream .pdf

# PREVENT ACCESS TO CONFIG
<Files config.php>
order allow,deny
deny from all
</Files>

# CACHING
# http://httpd.apache.org/docs/current/mod/mod_headers.html
<FilesMatch "\.(js|css|ico|png|gif|jpg)$">
Header set Cache-Control "max-age=172800, public, must-revalidate"
#Header set Expires "Thu, 15 Apr 2011 20:00:00 GMT"
</FilesMatch>

# PREVENT ACCESS TO STATS UPDATE SCRIPT AS IT'S CLI ONLY
<Files stats_update.php>
order allow,deny
deny from all
</Files>

Redirect 302 /preview http://otherdomain.com/documents/preview
Redirect 302 /sample http://otherdomain.com/documents/preview

RewriteEngine On

# REWRITE NON-WWW TO WWW
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule (.*) http://www.%{HTTP_HOST}/$1 [R=301]

RewriteRule ^about/?$ /index.php [L]
RewriteRule ^contact/?$ /contact.php [L]
RewriteRule ^home/?$ /home.php [L]
RewriteRule ^order/?$ /order.php [L]

# MAINTAINANCE
#RewriteCond %{REMOTE_HOST} !^123\.123\.123\.123
#RewriteCond %{REQUEST_URI} !^/maintainance\.html$
#RewriteRule ^(.*)$ /maintainance.html [R=302,L]

编辑:这可能与 cPanel 处理主域和附加域的方式有关吗?
在 cPanel 帐户中,您有一个主域,其文件位于 public_html 下然后定义其文件位于 public_html/addondomain.com/ 下的插件域(或子域)

主域的 .htaccess 位于 public_html/.htaccess 吗?影响/覆盖 public_html/addondomain.com/.htaccess 的插件域?
我知道 .htaccess 确实会通过目录向下级联,但即使在特定域的 DocumentRoot 之上也是如此,例如:在此插件域的情况下?

编辑 2:仅供引用,这里是对两个 HTTP 请求的响应,绕过任何缓存

root@vps [/home/username]#curl -i 'http://www.mydomain.com/config.php'
HTTP/1.1 403 Forbidden
Date: Sun, 16 Sep 2012 19:05:10 GMT
Server: Apache
Content-Length: 331
Content-Type: text/html; charset=iso-8859-1


root@vps [/home/username]# curl -i 'http://mydomain.com/config.php'
HTTP/1.1 301 Moved Permanently
Date: Sun, 16 Sep 2012 19:05:20 GMT
Server: Apache
Location: http://www.mydomain.com/403.shtml
Content-Length: 244
Content-Type: text/html; charset=iso-8859-1

您会看到第二个获得 301 重定向,但它重定向到 403.shtml。所以403.shtml在重写www之前就已经被注入(inject)了。发生了。

最佳答案

这在普通 Apache 安装中无法重现,因此我开始进一步询问 cPanel。因此,经过大量的研究后,我找到了这个问题。 cPanel 确实为您设置了 ErrorDocument 指令,但它一点也不聪明。特别是当它将 ErrorDocuments 设置为与 Apache 默认值明显相同的文档时。
由于 ErrorDocument cPanel 屏幕为空白,因此发生这种情况的位置并不明显。

cPanel 的 httpd.conf 是由相当多的包含的配置构建的,并且隐藏着......

/usr/local/apache/conf/includes/errordocument.conf
...
# 403 - Forbidden
ErrorDocument 403 /403.shtml

这就是 403.shtml 出现在请求中的地方。 cPanel 为我设置了错误文档。为了避免在 403 上看到 404 的困惑,我设置了自己的 403 错误消息,这样至少它们是一致的。

我希望这可以帮助别人!

关于apache - htaccess 文件拒绝所有,重定向到 404 在 403.shtml 上找不到,但未定义自定义错误页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12192681/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com