406服务器错误

时间:2012-08-23 03:19:28

标签: apache .htaccess redirect url-rewriting

我的网站在我们的本地计算机上以及我们的测试服务器上都没有错误。然而,当我们将它放在网站的实时服务器上时,我们会随机发生406错误。

例如,如果我们访问website.com/clothes或website.com/clothes/tshirts页面正确加载并正确显示图像而不会出错。如果我们导航到website.com/clothes/tshirts/bluepinned产品图片(website.com/images/clothes/tshirts/bluepinned.jpg)无法加载,在firebug中出现406错误。如果我们缓存刷新页面(CTRL + F5)所有页面资源(如样式表,图像等)产生406错误,如果再次刷新整个服务器似乎超时并且没有显示任何内容。如果我重新启动路由器(给我一个新的IP地址),我可以再次访问该网站。

网址:

website.com/clothes <- category showing all sub-categories and products (using product thumb image)
website.com/clothes/tshirts <- sub-category showing all products (using product thumb image)
website.com/clothes/tshirts/bluepinned <- individual product page (using large product image)

htaccess的:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(clothes)/([^/\.]+)/([^/\.]+)/?$ products.php?c=$1&sc=$2&p=$3 [NC,L,QSA] 
RewriteRule ^(clothes)/([^/\.]+)/?$ products.php?c=$1&sc=$2 [NC,L,QSA] 
RewriteRule ^(clothes)/?$ products.php?c=$1 [NC,L,QSA] 

我检查了phpinfo - 找不到mod_security。在那些正在加载的页面上没有什么特别的 - 基本的HTML页面,PHP类调用加载类别/子类别/产品。没有Javascript或POST或AJAX。

任何可能导致406的想法?

更新1: 这是Firebug / Firefox中的标题响应(删除了Host和Referrer):

Response Headers:
Cache-Control   no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Connection  Keep-Alive
Content-Type    text/html
Date    Thu, 23 Aug 2012 05:36:54 GMT
Expires Thu, 19 Nov 1981 08:52:00 GMT
Keep-Alive  timeout=5, max=99
Pragma  no-cache
Server  Apache
Transfer-Encoding   chunked
X-Powered-By    PHP/5.2.17

Request Headers:
Accept  image/png,image/*;q=0.8,*/*;q=0.5
Accept-Encoding gzip, deflate
Accept-Language en-us,en;q=0.5
Connection  keep-alive
Cookie  __utma=175298877.1838807483.1343995016.1345683454.1345698456.35; __utmz=175298877.1344487166.16.3.utmcsr=google.com|utmccn=(referral)|utmcmd=referral|utmcct=/imgres; __utmc=175298877; PHPSESSID=0d6664f0306618ac0f4218895efc4404; __utmb=175298877.2.10.1345698456
User-Agent  Mozilla/5.0 (Windows NT 6.1; WOW64; rv:14.0) Gecko/20100101 Firefox/14.0.1

更新2: Google Chrome中的标头响应:

Request Method:GET
Status Code:406 Not Acceptable

Request Headers
Accept:*/*
Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Connection:keep-alive
Cookie:PHPSESSID=d5b28960a6d3e73c7db5a3808432ee71; __utma=175298877.1644911186.1345701704.1345701704.1345701704.1; __utmb=175298877.2.10.1345701704; __utmc=175298877; __utmz=175298877.1345701704.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.83 Safari/537.1

Response Headers
Cache-Control:no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Connection:Keep-Alive
Content-Type:text/html
Date:Thu, 23 Aug 2012 06:02:16 GMT
Expires:Thu, 19 Nov 1981 08:52:00 GMT
Keep-Alive:timeout=5, max=99
Pragma:no-cache
Server:Apache
Transfer-Encoding:chunked
X-Powered-By:PHP/5.2.17

更新3: 添加了本地响应(有效!)

Response Headers
Accept-Ranges   bytes
Connection  Keep-Alive
Content-Length  28212
Content-Type    image/jpeg
Date    Thu, 23 Aug 2012 05:58:31 GMT
Etag    "40000000cd15a-6e34-4c6eb29ada7fc"
Keep-Alive  timeout=5, max=77
Last-Modified   Fri, 10 Aug 2012 15:40:25 GMT
Server  Apache/2.2.21 (Win64) mod_ssl/2.2.21 OpenSSL/1.0.0d PHP/5.3.8

Request Headers
Accept  image/png,image/*;q=0.8,*/*;q=0.5
Accept-Encoding gzip, deflate
Accept-Language en-us,en;q=0.5
Connection  keep-alive
Cookie  PHPSESSID=mjete8dhhn9abi9fkdfkce0kh2
User-Agent  Mozilla/5.0 (Windows NT 6.1; WOW64; rv:14.0) Gecko/20100101 Firefox/14.0.1

所以我想如果文件是.jpg,图像/ *会允许吗?

1 个答案:

答案 0 :(得分:-1)

您必须使用REQUEST_URI代替REQUEST_FILENAME 或将localpath附加到重写规则

来自apache doc的

REQUEST_URI

  

请求的URI的路径组件,例如   &#34; /index.html" ;.这显然排除了查询字符串   可用作名为QUERY_STRING的变量。

REQUEST_FILENAME

  

匹配的文件或脚本的完整本地文件系统路径    请求,如果这已经由服务器确定    REQUEST_FILENAME被引用。否则,例如在使用时    虚拟主机上下文,与REQUEST_URI相同。

还要结帐LogLevel alert rewrite:trace3,了解更换的内容和匹配的内容