I am trying to develop a "semi-permanent" redirect in IIS 8.5 using a 301 response along with cache expiration header(s), perhaps a max-age or cache-control with a reasonable expiration. However IIS's URL Rewrite doesn't seem to support adding response headers to a redirect rule. I see how to affect the cache at a larger scope, like this, but not how to apply them to individual redirects. I.e.:
<rule name="foo" stopProcessing="true">
<match url="foo" />
<conditions>
<add input="{URL}" pattern="/foo($|\/$)" />
</conditions>
<action type="Redirect" url="http://domain.com/full_url_for_now" redirectType="Permanent" someParameterThatLetsMeSetResponseHeaders="max-age:3600"/>
</rule>
Thanks for any advice. I'm guessing there's some other way to do this for individual rules/paths/etc., but no luck finding it. If it's not possible, then I'll have to set the cache parameters at a higher level.
Why: the redirect is for a vanity URL; the path will be the same for a month or two but may change after that. Straight 301 will cache permanently in some browsers. 302/307 will cause the the vanity URL to be indexed, which would mess up my SEO.
The cache response header goes in outbound rules:
<outboundRules>
<rule name="Require clients to revalidationpermanent redirects">
<match serverVariable="RESPONSE_Cache_Control" pattern=".*" />
<conditions>
<add input="{RESPONSE_STATUS}" pattern="301" />
</conditions>
<action type="Rewrite" value="public, must-revalidate, max-age=0"/>
</rule>
</outboundRules>
Result:
Fiddler Screenshot:
This will help you avoid the horror that cannot be undone with 301 permanent redirects. I encourage you to read this excellent article.
With credit to http://www.gillsoft.ie/using-url-rewrite-to-improve-your-site-performance-001
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With