Skip to content

Instantly share code, notes, and snippets.

@tophatsteve
Created March 3, 2014 08:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tophatsteve/9320858 to your computer and use it in GitHub Desktop.
Save tophatsteve/9320858 to your computer and use it in GitHub Desktop.
Force PDFs to always download rather than open in brower
<system.webServer>
<!-- other system.webServer stuff -->
<rewrite>
<outboundRules>
<rule name="Forcing Download for PDFs" preCondition="IsPDF">
<match serverVariable="RESPONSE_Content-Disposition" pattern=".*" />
<conditions>
<add input="{REQUEST_FILENAME}" pattern="(.*)\\([^/]+)\.pdf$" />
</conditions>
<action type="Rewrite" value="attachment; filename={C:2}.pdf" />
</rule>
<preConditions>
<preCondition name="IsPDF">
<add input="{REQUEST_FILENAME}" pattern="\.pdf$" />
</preCondition>
</preConditions>
</outboundRules>
</rewrite>
<!-- other system.webServer stuff -->
</system.webServer>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment