0

我有一个网站,它可以在我们的本地机器和我们的测试服务器上正常运行。但是,当我们将它放在实时服务器上时,我们会随机出现 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)

.ht 访问:

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:谷歌浏览器中的标题响应:

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,image/* 会允许吗?

4

1 回答 1

-1

您必须使用REQUEST_URI而不是REQUEST_FILENAME 或将本地路径附加到您的重写规则

来自 apache 文档:

REQUEST_URI

请求的 URI 的路径组件,例如“/index.html”。这特别排除了作为其自己的变量 QUERY_STRING 可用的查询字符串。

REQUEST_FILENAME

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

还结帐LogLevel alert rewrite:trace3以清楚地了解替换的内容和匹配的内容

于 2012-08-23T07:23:35.580 回答