2010/10/28 10:45
文章作者:Enjoy 转载请注明原文链接。
在web服务器端(nginx)用rewrite设置跳转rewrite ^/1.htm$ http://www.9enjoy.com permanent;
rewrite ^/2.htm$ http://www.9enjoy.com last;
rewrite ^/2.htm$ http://www.9enjoy.com last;
http://192.168.1.158:843/1.htm
响应头信息
Server nginx/0.8.34
Date Thu, 28 Oct 2010 01:59:00 GMT
Content-Type text/html
Content-Length 185
Connection keep-alive
Location http://www.9enjoy.com
缓存:
Last Modified Thu Oct 28 2010 09:59:36 GMT+0800
Last Fetched Thu Oct 28 2010 09:59:38 GMT+0800
Expires Sun Feb 07 2106 14:28:15 GMT+0800
Data Size 0
总计接收:382B,其中响应头185B。
http://192.168.1.158:843/2.htm
响应头信息
Server nginx/0.8.34
Date Thu, 28 Oct 2010 01:59:27 GMT
Content-Type text/html
Content-Length 161
Connection keep-alive
Location http://www.9enjoy.com
缓存:
Last Modified Thu Oct 28 2010 10:00:02 GMT+0800
Last Fetched Thu Oct 28 2010 10:00:02 GMT+0800
Expires Thu Jan 01 1970 08:00:00 GMT+0800
Data Size 0
总计接收:358B,其中响应头161B。
301的Expired,直接设到了2106-02-07 22:28:15,而302的expired直接设为了最小的时间戳1970-01-01。
因此,对于301的请求,浏览器默认会给一个很长的缓存,而302的请求是不缓存的。
再用程序写301跳转测试:
http://192.168.1.158:843/3.php
Header( "HTTP/1.1 301 Moved Permanently" );
Header( "Cache-Control: max-age=86400");
Header( "Location: http://www.9enjoy.com" );
Header( "Cache-Control: max-age=86400");
Header( "Location: http://www.9enjoy.com" );
响应头信息
Server nginx/0.8.34
Date Thu, 28 Oct 2010 02:12:02 GMT
Content-Type text/html
Transfer-Encoding chunked
Connection keep-alive
X-Powered-By PHP/5.2.10
Cache-Control max-age=86400
Location http://www.9enjoy.com
缓存:
Last Modified Thu Oct 28 2010 10:12:38 GMT+0800
Last Fetched Thu Oct 28 2010 10:12:38 GMT+0800
Expires Fri Oct 29 2010 10:12:02 GMT+0800
Data Size 0
Fetch Count 12
Device disk
总计接收:259B,其中响应体为0字节。
Header( "HTTP/1.1 301 Moved Permanently" );
Header( "Location: http://www.9enjoy.com" );
Header( "Location: http://www.9enjoy.com" );
Last Modified Thu Oct 28 2010 10:17:28 GMT+0800
Last Fetched Thu Oct 28 2010 10:17:29 GMT+0800
Expires Sun Feb 07 2106 14:28:15 GMT+0800
Data Size 0
总计接收:229B,其中响应体为0字节。
这样看来,用php写的301跳转还比服务端直接设置的省100多个字节,当然实际上,这一点差别基本上没意义。根据情况,用那种方法方便就用什么方法。查看更多的301跳转方法
但是,无论我使用哪种301跳转的方式,在更换了跳转地址后,直接打开页面,会跳转到新的地址上,看起来没有使用到缓存啊!这个问题还没搞明白。