Last active
April 14, 2020 15:56
-
-
Save bmatthewshea/151407753bd8b01ced9d422b7a65587e to your computer and use it in GitHub Desktop.
Web.config - IIS - AWS/EC2 REWRITE - Rewrite APEX, NON-WWW & NON-SSL - Catchall
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
<configuration> | |
<system.webServer> | |
... | |
<rewrite> | |
<rules> | |
<!-- To work, DNS subdomains must be wildcarded to this site. --> | |
<!-- Also, this first rule must be listening for all incoming requests/"default web server". --> | |
<!-- The first rule runs on anything that doesn't match "www.example.com". --> | |
<rule name="Catchall redirect to www" stopProcessing="true"> | |
<match url="(.*)" ignoreCase="true" /> | |
<conditions logicalGrouping="MatchAny" trackAllCaptures="false"> | |
<add input="{HTTP_HOST}" pattern="^www\.example\.com$" negate="true" /> | |
</conditions> | |
<action type="Redirect" url="https://www.example.com/{R:0}" redirectType="Found" /> | |
</rule> | |
<rule name="Redirect HTTP to HTTPS" stopProcessing="true"> | |
<match url="(.*)" ignoreCase="true" /> | |
<conditions logicalGrouping="MatchAny" trackAllCaptures="false"> | |
<!-- Uncomment 2nd line for AWS EC2 SSL detection - uncomment 1st line for normal detection: --> | |
<!-- add input="{HTTPS}" ignoreCase="true" pattern="^OFF$" / --> | |
<add input="{HTTP_X_FORWARDED_PROTO}" pattern="https" negate="true" /> | |
</conditions> | |
<action type="Redirect" url="https://www.example.com/{R:0}" redirectType="Permanent" /> | |
</rule> | |
</rules> | |
</rewrite> | |
... | |
</system.webServer> | |
</configuration> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment