Last active
June 30, 2021 21:53
-
-
Save stevensk/c8108311b82ba1591cb1be018bbe0119 to your computer and use it in GitHub Desktop.
IIS URL Rewrite for Site Maintenance
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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> |
Thanks for the code. So userfull.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Provides a solution for redirecting all requests not originating from a white listed IP address to a maintenance placeholder page. This allows requests originating from a white listed IP address to test site functionality during the maintenance period.