重定向到PDF时Apache/PHP HTTP重定向问题/循环


Apache/PHP HTTP Redirect issue/loop when redirecting to PDF

第一次在此处发布。

我正在经历一个最奇怪的问题,老实说我以前从未见过。我有一个内部URL转发服务,我的客户可以在这里创建一个关键字,并将该关键字重定向到他们指定的目标。这一直很好,然而,今天我被告知重定向到PDF的问题。

我的一位用户创建了一个PDF的短URL,并抱怨点击统计数据太差了。当我研究这个问题时,我注意到相当多的客户尝试了我称之为重定向循环的方法。

从本质上讲,他们一次又一次地请求不同字节范围的短URL。这种情况不断发生;有时我会连续看到60+70个。我试过更改缓存头等,但我所做的似乎都无法解决这个问题。甚至试着把302改成301。运气不好(如有任何反馈,我们将不胜感激。谢谢大家!

以下是我通过tcpdump:捕获的一个片段

GET /ShowcaseGuide HTTP/1.1
Accept: */*
Referer: wwww.someinternalserver.com
Accept-Language: en-US
User-Agent: Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)
Accept-Encoding: gzip, deflate
Host: goto.mydomain.org
DNT: 1
Connection: Keep-Alive
Cookie: s_pers=xxxxxx

HTTP/1.1 302 Found
Date: Tue, 19 Nov 2013 20:09:52 GMT
Server: Apache/2.2.3 (Red Hat)
X-Powered-By: PHP/5.3.3
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: private, must-revalidate
Pragma: no-cache
Location: http://internalserver.mydomain.org/links/Get_the_Most_Out_of_the_Showcase.pdf
Vary: Accept-Encoding
Content-Encoding: gzip
Content-Length: 20
Keep-Alive: timeout=5, max=200
Connection: Keep-Alive
Content-Type: text/html; charset=UTF-8
GET /ShowcaseGuide HTTP/1.1
Accept: */*
Range: bytes=2178560-2179071, 2179072-2179369
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)
Host: goto.mydomain.org
DNT: 1
Connection: Keep-Alive
Cookie: s_pers=xxxxxx
HTTP/1.1 302 Found
Date: Tue, 19 Nov 2013 20:09:56 GMT
Server: Apache/2.2.3 (Red Hat)
X-Powered-By: PHP/5.3.3
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: private, must-revalidate
Pragma: no-cache
Location: http://internalserver.mydomain.org/links/Get_the_Most_Out_of_the_Showcase.pdf
Vary: Accept-Encoding
Content-Encoding: gzip
Content-Length: 20
Keep-Alive: timeout=5, max=199
Connection: Keep-Alive
Content-Type: text/html; charset=UTF-8
GET /ShowcaseGuide HTTP/1.1
Accept: */*
Range: bytes=1867776-1884159
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)
Host: goto.mydomain.org
DNT: 1
Connection: Keep-Alive
Cookie: s_pers=xxxxxx
HTTP/1.1 302 Found
Date: Tue, 19 Nov 2013 20:09:57 GMT
Server: Apache/2.2.3 (Red Hat)
X-Powered-By: PHP/5.3.3
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: private, must-revalidate
Pragma: no-cache
Location: http://internalserver.mydomain.org/links/Get_the_Most_Out_of_the_Showcase.pdf
Vary: Accept-Encoding
Content-Encoding: gzip
Content-Length: 20
Keep-Alive: timeout=5, max=198
Connection: Keep-Alive
Content-Type: text/html; charset=UTF-8

也许可以这样做,而不是使用重定向?应在浏览器中显示

/ShowcaseGuide/index.php:

<?php
header('Content-type: application/octet-stream');
header('Content-Disposition: inline; filename="Get_the_Most_Out_of_the_Showcase.pdf"');
readfile('../links/Get_the_Most_Out_of_the_Showcase.pdf'); 
?>

可能是浏览器开始下载PDF,然后转到初始页面(/ShowcaseGuide/index.php),然后再次重定向到同一文件。如果发生这种情况,可能与浏览器有关。

如果希望下载第二行header而不是在浏览器中查看,请将其更改为header('Content-Disposition: attachment; filename="Get_the_Most_Out_of_the_Showcase.pdf"');