Skip to content

Instantly share code, notes, and snippets.

@mawiseman
Created February 28, 2023 22:11
Show Gist options
  • Select an option

  • Save mawiseman/b03848d44dc94a1bf131569da879ee01 to your computer and use it in GitHub Desktop.

Select an option

Save mawiseman/b03848d44dc94a1bf131569da879ee01 to your computer and use it in GitHub Desktop.

Revisions

  1. mawiseman created this gist Feb 28, 2023.
    33 changes: 33 additions & 0 deletions UrlRewriteRules.config
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    <rule name="ForceWWW" stopProcessing="true">
    <match url=".*" ignoreCase="true" />
    <conditions>
    <add input="{HTTP_HOST}" pattern="^yoursite.com" />
    </conditions>
    <action type="Redirect" url="https://www.yoursite.com/{R:0}" redirectType="Permanent" />
    </rule>

    <rule name="HTTPtoHTTPS" stopProcessing="true">
    <match url="(.*)" ignoreCase="false" />
    <conditions>
    <add input="{HTTPS}" pattern="off" />
    </conditions>
    <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" />
    </rule>

    <rule name="RemoveTrailingSlash">
    <match url="(.*)/$" />
    <conditions>
    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
    </conditions>
    <action type="Redirect" redirectType="Permanent" url="{R:1}" />
    </rule>

    <rule name="ToLowerCase">
    <match url=".*[A-Z].*" ignoreCase="false" />
    <action type="Redirect" url="{ToLower:{R:0}}" redirectType="Permanent" />
    <conditions>
    <add input="{URL}" pattern="WebResource.axd" negate="true" />
    <add input="{URL}" pattern="ScriptResource.axd" negate="true" />
    </conditions>
    </rule>