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: ##/100FAILED - (No max-age or expires) - http://example.com/sectionSo 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 PermanentlyDate: Sun, 08 Mar 2015 18:09:18 GMTServer: ApacheLocation: http://example.com/newsectionContent-Type: text/html; charset=iso-8859-1Is 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?
Trying to add cache header to 301 pages made by ModRewrite
redirects;301 redirect;mod rewrite;http headers;302 redirect
You could set an environment variable in the RewriteRule directive and set the Cache-Control header conditionally based on the presence of this environment variable...RewriteRule ^section$ /newsection [NC,L,R=302,E=cachesection:1]Header always set Cache-Control max-age=86400 env=cachesection...to cache the temporary redirect for 1 day.