htaccess文件全部拒绝,重定向到403.shtml上找不到的404,但没有定义自定义错误页面

bat*_*tad 2 apache .htaccess custom-error-pages

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

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

未找到
在此服务器上找不到请求的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]
Run Code Online (Sandbox Code Playgroud)

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

主域的.htaccess是否public_html/.htaccess会影响/覆盖插件域的.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
Run Code Online (Sandbox Code Playgroud)

你看到第二个获得301重定向但它重定向到403.shtml.所以在重写到www之前已经注入了403.shtml.发生.

bat*_*tad 5

这在vanilla Apache安装上是不可重现的,所以我开始进一步询问cPanel.因此,经过大量的捣乱,我已经找到了问题.cPanel确实为你设置了ErrorDocument指令,它根本不是很聪明.特别是当它将ErrorDocuments设置为与Apache默认值明显相同的文档时.
由于ErrorDocument cPanel屏幕为空白,因此发生这种情况并不明显.

cPanel的httpd.conf是由很多包含的配置构建的,隐藏在那里......

/usr/local/apache/conf/includes/errordocument.conf
...
# 403 - Forbidden
ErrorDocument 403 /403.shtml
Run Code Online (Sandbox Code Playgroud)

所以我们去了,403.shtml出现在请求中.cPanel为我设置错误文档.为了避免在403上看到404的混乱,我设置了自己的403错误消息,所以至少它们是一致的.

我希望这可以帮助别人!