I have several URLs on my website that get redirected to other URLs using Mod-Rewrite. For example:
RewriteRule ^section$ /newsection [NC,L,R=301]
The above rule redirects http://example.com/section to http://example.com/newsection (I'm using example.com here because I don't want to use my real URL as it is irrelevant to my question)
I then proceeded to test the page using webpagetest optimizer at webpagetest.org and The redirect page received and error as follows:
Leverage browser caching of static assets: ##/100
FAILED - (No max-age or expires) - http://example.com/section
So then I proceeded to visit the same page via CURL command line tool and the results are as follows:
Body:
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>301 Moved Permanently</title>
</head><body>
<h1>Moved Permanently</h1>
<p>The document has moved <a href="http://example.com/newsection">here</a>.</p>
</body></html>
And headers:
HTTP/1.1 301 Moved Permanently
Date: Sun, 08 Mar 2015 18:09:18 GMT
Server: Apache
Location: http://example.com/newsection
Content-Type: text/html; charset=iso-8859-1
Is there a way that I can add a cache-control or an expires header with a far future date only to pages that return a 301 or 302 status code so that users dont have to make a trip to the network only to load a redirection page?
webpagetest.org
s "error" would seem to be a bit strict - to the point of being incorrect - if it is indeed refering to the redirect itself and not the target? A 301 redirect is by definition "permanent" and all modern browsers do appear to cache them to some extent (as suggested by RFC 2616).