Skip to content

Instantly share code, notes, and snippets.

@stevensk
Last active June 30, 2021 21:53
Show Gist options
  • Save stevensk/c8108311b82ba1591cb1be018bbe0119 to your computer and use it in GitHub Desktop.
Save stevensk/c8108311b82ba1591cb1be018bbe0119 to your computer and use it in GitHub Desktop.
IIS URL Rewrite for Site Maintenance
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rewriteMaps>
<rewriteMap name="MaintenanceIpAddressWhitelist" defaultValue="">
<!-- add allowed IP addresses to grant access during maintenance period -->
<add key="192.168.0.1" value="1" />
<add key="127.0.0.1" value="1" />
</rewriteMap>
</rewriteMaps>
<rules>
<!-- if request is not from a white listed IP and is not for the maintenance page then redirect to maintenance page -->
<rule name="Maintenance Redirect">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{MaintenanceIpAddressWhitelist:{REMOTE_ADDR}}" matchType="Pattern" pattern="1" negate="true" />
<add input="{REQUEST_URI}" pattern="^/maintenance.html$" negate="true" />
</conditions>
<action type="Redirect" url="/maintenance.html" appendQueryString="false" redirectType="Temporary"/>
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
@mariobot
Copy link

Thanks for the code. So userfull.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment