2

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

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

未找到
在此服务器上未找到请求的 URL /403.shtml。
此外,在尝试使用 ErrorDocument 处理请求时遇到 404 Not Found 错误。

如果我试图定义自定义错误文档,我通常会期望这一点,但在这种情况下,我不是!
使该域与同一 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/

主域的 .htaccesspublic_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 之前已经被注入了。发生。

4

2 回答 2

5

这在香草 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 错误消息,因此至少它们是一致的。

我希望这可以帮助某人!

于 2012-09-17T09:08:23.900 回答
1

您的 htaccess 文件不会导致自定义错误页面。如果没有任何其他 htaccess 文件,则问题可能出在 cPanel 上,它有自己的设置自定义错误页面的方式

于 2012-08-30T17:48:07.463 回答