htaccess文件从所有拒绝,重定向到404 403.shtml没有找到,但没有定义自定义错误页 [英] htaccess file deny from all, redirects to 404 not found on 403.shtml but no custom error pages defined

查看:969
本文介绍了htaccess文件从所有拒绝,重定向到404 403.shtml没有找到,但没有定义自定义错误页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设立在的cPanel一个新的附加域快速的内部项目。这种特殊的一个人安装了SSL证书。我建设我的.htaccess并增加了一个<文件的config.php> 指令所有使否认我config.php文件无法访问。我认识到,将其存储在Web根目录之外的理想,但我不能在这种情况下。

I'm setting up a quick internal project in a new addon domain in cPanel. This particular one has an SSL cert installed. I was building my .htaccess up and added a <Files config.php> directive to deny from all so that my config.php file isn't accessible. I realise that storing it outside of the web root is the ideal but I can't in this case.

通常我会想到的是,当在浏览器中,我将获得Apache默认的403禁止页转到 www.domain.com/config.php 。这是在同一台服务器上的其他领域发生了什么。但在这种情况下,我被赋予了404未找​​到错误,说明:

Normally I would expect that when going to www.domain.com/config.php in a browser that I would get Apache's default 403 Forbidden page. This is what happens on other domains on the same server. But in this case I'm being given a 404 not found error, stating:

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

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证书的事实。而这404错误是相同的,不管使用HTTP或HTTPS进行导航的。我已经试过清除缓存,仍然是相同的。

I would normally expect this if I was attempting to define custom error documents but in this case, I'm not!
The only thing that makes this domain different to all the others in the same cPanel account is the fact it has an SSL certificate. And this 404 error is the same regardless of navigating using http or https. I've tried clearing cache and still the same.

任何人都可以看到任何下文我的.htaccess可能会导致什么呢?

Can anyone see anything in my .htaccess below that might be causing this?

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 /

Could it be anything to do with the way cPanel handles primary and addon domains?
In a cPanel account you have a primary domain whose files live under public_html then you define addon domains (or subdomains) whose files live under public_html/addondomain.com/

会在的public_html /的.htaccess 的htaccess的主域会影响/覆盖的插件域的的public_html / addondomain.com /的.htaccess
我知道的.htaccess并通过目录级联下降,但就是这样,即使上述特定域的DocumentRoot,如:?这个附加域的情况下

Would the .htaccess for the primary domain at public_html/.htaccess be affecting/overriding that of addon domains at public_html/addondomain.com/.htaccess?
I know .htaccess does cascade down through directories but is that the case even above a particular domain's DocumentRoot, e.g.: in the case of this addon domain?

编辑2:只是为了信息在这里是响应这两个HTTP请求,绕过任何缓存

EDIT 2: Just for info here are the responses to both HTTP requests, bypassing any caching

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之前注入。发生的情况。

You see the 2nd one gets the 301 redirect but it's redirecting to the 403.shtml. So the 403.shtml has already been injected before the rewrite to the www. happens.

推荐答案

这是不可复制的香草Apache安装,所以我就开始进一步询问的cPanel。因此,大量的摆弄周围后,我已经找到了问题。的cPanel确实设置ErrorDocument指令给你,这不是很聪明的。特别是当它设置出错页面到是明显等同于Apache的默认文件。
这不是很明显的地方出现这种情况,无论是作为的ErrorDocument的cPanel屏幕是空白的。

This was not reproducible on a vanilla Apache installation so I started to further interrogate cPanel. So after plenty of mucking around I have tracked down the issue. cPanel does indeed set the ErrorDocument directive for you and it's not very clever at all. Especially when it sets the ErrorDocuments to documents that are visibly identical to the Apache defaults.
It's not obvious where this happens either as the ErrorDocument cPanel screen is blank.

cPanel的httpd.conf文件是由相当多的内置包含的configs和藏有...

cPanel's httpd.conf is built from quite a few included configs and tucked away there is...

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

所以我们走,这也正是403.shtml正出现在该请求。 cPanel的设置错误文档我。为了避免出现在403的404,我把我自己的403错误消息,所以至少它们是一致的困惑。

So there we go, that's where the 403.shtml is appearing in the request. cPanel's setting the error documents for me. To avoid the confusion of seeing the 404 on the 403 I've set my own 403 error message so at least they are consistent.

我希望这可以帮助别人了!

I hope this helps someone out!

这篇关于htaccess文件从所有拒绝,重定向到404 403.shtml没有找到,但没有定义自定义错误页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆