Forked from developerdizzle/IIS Rewrite Cheat Sheet
Last active
August 29, 2015 14:19
-
-
Save digggggggggg/63a8c8bb8cc586c717ce to your computer and use it in GitHub Desktop.
This file contains 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
<rewrite> | |
<!-- Have a bunch of redirects? Put them in a separate file --> | |
<rules configSource="Rewrites.config" /> | |
<rules> | |
<!-- Simple rewrite --> | |
<rule name="Simple rewrite" stopProcessing="true"> | |
<match url="^path/sub path/page\.aspx$" /> | |
<action type="Rewrite" url="/newpath.aspx" /> | |
</rule> | |
<!-- Simple redirect --> | |
<rule name="Simple redirect" stopProcessing="true"> | |
<match url="^path/sub path/page\.aspx$" /> | |
<action type="Redirect" url="/newpath.aspx" /> | |
</rule> | |
<!-- Based on query string --> | |
<rule name="Based on query string" stopProcessing="true"> | |
<match url="^path/sub path/page\.aspx$" /> | |
<conditions> | |
<add input="{QUERY_STRING}" pattern="^parameter=value$" /> | |
</conditions> | |
<action type="Redirect" url="/newpage.aspx" appendQueryString="false" /> | |
</rule> | |
<!-- Based on host name --> | |
<rule name="Based on host name" stopProcessing="true"> | |
<match url="^path/sub path/page\.aspx$" /> | |
<conditions> | |
<add input="{HOST_NAME}" pattern="^(www)?wakefly\.net$" /> | |
</conditions> | |
<action type="Redirect" url="http://www\.wakefly\.com/newpage.aspx" /> | |
</rule> | |
<!-- Canonical redirect --> | |
<rule name="Canonical redirect" stopProcessing="true"> | |
<match url="(.*)" /> | |
<conditions> | |
<add input="{HOST_NAME}" pattern="^www\.wakefly\.com$" negate="true" /> | |
</conditions> | |
<action type="Redirect" url="http://www\.wakefly\.com/{R:1}" /> | |
</rule> | |
<!-- Force HTTPS --> | |
<rule name="Force HTTPS" stopProcessing="true"> | |
<match url="(.*)" /> | |
<conditions> | |
<add input="{HTTPS}" pattern="^OFF$" /> | |
</conditions> | |
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" /> | |
</rule> | |
<!-- Stop hot-links --> | |
<rule name="Stop hot-links"> | |
<match url=".*\.(gif|jpg|png)$"/> | |
<conditions> | |
<add input="{HTTP_REFERER}" pattern="^$" negate="true" /> | |
<add input="{HTTP_REFERER}" pattern="^http://wakefly\.com/.*$" negate="true" /> | |
</conditions> | |
<action type="Rewrite" url="/images/troll_face.png" /> | |
</rule> | |
<!-- | |
MORE RULES FROM: | |
http://ruslany.net/2009/04/10-url-rewriting-tips-and-tricks/ | |
---> | |
<rule name="Remove trailing slash" stopProcessing="true"> | |
<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="Add trailing slash" stopProcessing="true"> | |
<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="Convert to lower case" stopProcessing="true"> | |
<match url=".*[A-Z].*" ignoreCase="false" /> | |
<action type="Redirect" url="{ToLower:{R:0}}" redirectType="Permanent" /> | |
</rule> | |
<rule name="Canonical Host Name" stopProcessing="true"> | |
<match url="(.*)" /> | |
<conditions> | |
<add input="{HTTP_HOST}" negate="true" pattern="^ruslany\.net$" /> | |
</conditions> | |
<action type="Redirect" url="http://ruslany.net/{R:1}" redirectType="Permanent" /> | |
</rule> | |
<rule name="Redirect to HTTPS" stopProcessing="true"> | |
<match url="(.*)" /> | |
<conditions> | |
<add input="{HTTPS}" pattern="^OFF$" /> | |
</conditions> | |
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" /> | |
</rule> | |
<rule name="Return 503" stopProcessing="true"> | |
<match url="^products/sale/.*" /> | |
<action type="CustomResponse" statusCode="503" | |
subStatusCode="0" | |
statusReason="Site is unavailable" | |
statusDescription="Site is down for maintenance" /> | |
</rule> | |
<rule name="RewriteUserFriendlyURL1" stopProcessing="true"> | |
<match url="^([^/]+)/?$" /> | |
<conditions> | |
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> | |
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> | |
<!-- The following condition prevents rule from rewriting requests to .axd files --> | |
<add input="{URL}" negate="true" pattern="\.axd$" /> | |
</conditions> | |
<action type="Rewrite" url="article.aspx?p={R:1}" /> | |
</rule> | |
</rules> | |
</rewrite> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment