An analysis of HTTP message header Web page cache control and header common instruction introduction

Source: Internet
Author: User
Tags http authentication zip
This article is the HTTP Header page cache control and header commonly used instructions for a detailed analysis of the introduction, the need for friends to reference the  

The caching of the Web page is controlled by the "Cache-control" in the HTTP message header, and the common values are private, No-cache, Max-age, Must-revalidate, and so on, and the default is private. Its role is divided into the following situations according to different browsing methods:
(1) Open a new window
value is private, No-cache, Must-revalidate, then the server will be accessed when a new window is opened.
And if the Max-age value is specified, the server will not be accessed again in the time within this value, for example:
cache-control:max-age=5 (means to access the server again within 5 seconds of accessing this page)
(2) When the Address bar carriage return
value is private or must-revalidate, the server is accessed only for the first visit and is no longer accessible. The
value is No-cache and is accessed every time. The
value is Max-age, and no access is repeated until it expires.
(3) Press back button
to Private, must-revalidate, Max-age, no access,
value No-cache, repeat access every time
(4) Press the refresh button
to access this page does not leave a page backup on the Internet temporary article folder, regardless of the value, which will repeatedly access the
Cache-control value is "No-cache".
Additionally, caching is affected by specifying a "Expires" value. For example, to specify that the Expires value is a long past time, if you repeatedly press ENTER in the Address bar when you visit the network, you will repeat the visit each time: Expires:fri, Dec 1999 16:00:00 GMT
For example: Prohibit the page in IE cache
Strong>http Response message Header setting:
CacheControl = No-cache
Expires =-1
Expires is a good thing, if the Web page on the server often changes, set it to-1, indicating immediate expiration. If a page is updated daily 1 o'clock in the morning, you can set the expires to 1 o'clock in the morning the next day.
When the HTTP1.1 server specifies CacheControl = No-cache, the browser does not cache the Web page.
Legacy HTTP 1.0 Servers cannot use Cache-control headers.
Therefore, for backward compatibility with HTTP 1.0 servers, IE uses the Pragma:no-cache header to provide special support for HTTP.
Internet Explorer does not cache this response if the client communicates through a secure connection (https://)/with the server, and the server returns Pragma:no-cache headers in the response.
Note: Pragma:no-cache only prevents caching when used in a secure connection, and if used in an unsecured page, the processing is the same as expires:-1, and the page is cached but marked as immediately expired. The

Header common Directive
header is divided into three parts:
The first part is the HTTP protocol version (http-version);
The second part is state code (status);
Part III is divided into causal phrases (reason-phrase).

Copy Code code as follows:

//fix 404 Pages: Use this header directive to resolve the 404 header generated by the URL rewrite

header (' http/1.1 OK ');

//Set 404 Header: Page not found

header (' http/1.1 404 Not Found ');

//Page Permanent Redirect, you can tell the search engine to update their URLs

//Set Moved Permanently header (good for redrictions)

//Use with location header

header (' http/1.1 moved Permanently ');

//Access Limited

header (' http/1.1 403 Forbidden ');

//Server error

header (' http/1.1 Internal Server Error ');

//Redirect to a new location

//Redirect to a new location:

header (' location:;

after a period of delay

//Redrict with delay:

header (' refresh:10; Url= ');

print ' You'll be redirected in seconds ';

//Cover x-powered-by value

//override x-powered-by:php:

header (' x-powered-by:php/4.4.0 ');

header (' x-powered-by:brain/0.6b ');

//Content language (en = 中文版)

//Content language (en = 中文版)

header (' content-language:en ');

//Last modified (available at cache time)

//Last modified (good for caching)

$time = time ()-60; or Filemtime ($FN), etc

header (' last-modified: '. Gmdate (' d, D M Y h:i:s ', $time). ' GMT ');

//Tell the browser what to get is not yet updated

//header for telling the browser the content

//did not get changed

header (' http/1.1 304 not Modified ');

//Set the length of the content (available when cached):

//Set content length (good for caching):

header (' content-length:1234 ');

//used to download files:

//Headers for a download:

header (' Content-type:application/octet-stream ');

header (' content-disposition:attachment; filename= "");

header (' content-transfer-encoding:binary ');

//Disable caching of current document:

//Load the file to Send:readfile (' ');

//Disable caching of the current document:

header (' Cache-control:no-cache, No-store, max-age=0, Must-revalidate ');

header (' Expires:mon, 1997 05:00:00 GMT ');

//Set Content type:

//Date in the Pastheader (' Pragma:no-cache ');

//Set Content type:

header (' content-type:text/html; charset=iso-8859-1 ');

header (' content-type:text/html; Charset=utf-8 ');

//Plain text file

header (' Content-type:text/plain ');

JPG Picture

header (' content-type:image/jpeg ');

//ZIP file

header (' Content-type:application/zip ');

//PDF file

header (' content-type:application/pdf ');

//Audio MPEG (MP3,...) file

header (' content-type:audio/mpeg ');

//Flash animation//show sign In box

header (' Content-type:application/x-shockwave-flash ');

//Display Login dialog box, which can be used for HTTP authentication

header (' http/1.1 401 Unauthorized ');

header (' Www-authenticate:basic realm= ' top Secret ');

print ' Text that'll be displayed if the user hits cancel or ';

print ' enters wrong login data ';

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.