Last active
February 26, 2024 17:08
-
-
Save kipusoep/8179217 to your computer and use it in GitHub Desktop.
SEO redirects for web.config
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
<!-- SEO rules (from: http://www.seomoz.org/blog/what-every-seo-should-know-about-iis#chaining) --> | |
<!-- SEO | Section 1 | Whitelist --> | |
<rule name="Whitelist - Resources" stopProcessing="true"> | |
<match url="^(?:css/|scripts/|images/|install/|config/|umbraco/|umbraco_client/|base/|webresource\.axd|scriptresource\.axd|__browserLink|[^/]*/arterySignalR/.*)" /> | |
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" /> | |
<action type="None" /> | |
</rule> | |
<!-- SEO | Section 2 | Rewrites (chaining) --> | |
<rule name="SEO - Remove default.aspx" stopProcessing="false"> | |
<match url="(.*?)/?default\.aspx$" /> | |
<conditions logicalGrouping="MatchAll" trackAllCaptures="false"> | |
<add input="{HTTP_METHOD}" pattern="GET" /> | |
</conditions> | |
<action type="Rewrite" url="_{R:1}" /> | |
</rule> | |
<rule name="SEO - Remove trailing slash" stopProcessing="false"> | |
<match url="(.+)/$" /> | |
<conditions logicalGrouping="MatchAll" trackAllCaptures="false"> | |
<add input="{HTTP_METHOD}" pattern="GET" /> | |
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> | |
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> | |
</conditions> | |
<action type="Rewrite" url="_{R:1}" /> | |
</rule> | |
<rule name="SEO - Lower case" stopProcessing="false"> | |
<match url="(.*)" ignoreCase="false" /> | |
<conditions logicalGrouping="MatchAll" trackAllCaptures="false"> | |
<add input="{HTTP_METHOD}" pattern="GET" /> | |
<add input="{R:1}" pattern="[A-Z]" ignoreCase="false" /> | |
</conditions> | |
<action type="Rewrite" url="_{ToLower:{R:1}}" /> | |
</rule> | |
<!-- SEO | Section 3 | Redirecting --> | |
<rule name="SEO - HTTP canonical redirect" stopProcessing="true"> | |
<match url="^(_*)(.*)" /> | |
<conditions logicalGrouping="MatchAll" trackAllCaptures="true"> | |
<add input="{HTTP_HOST}" pattern="^www\.(.*)" /> | |
<add input="{HTTP_METHOD}" pattern="GET" /> | |
<add input="{SERVER_PORT}" pattern="80" /> | |
</conditions> | |
<action type="Redirect" url="http://{C:1}/{R:2}" /> | |
</rule> | |
<rule name="SEO - HTTPS canonical redirect" stopProcessing="true"> | |
<match url="^(_*)(.*)" /> | |
<conditions logicalGrouping="MatchAll" trackAllCaptures="true"> | |
<add input="{HTTP_HOST}" pattern="^www\.(.*)" /> | |
<add input="{HTTP_METHOD}" pattern="GET" /> | |
<add input="{SERVER_PORT}" pattern="443" /> | |
</conditions> | |
<action type="Redirect" url="http://{C:1}/{R:2}" /> | |
</rule> | |
<rule name="SEO - Non-canonical redirect" stopProcessing="true"> | |
<match url="^(_+)(.*)" /> | |
<conditions logicalGrouping="MatchAll" trackAllCaptures="false"> | |
<add input="{HTTP_METHOD}" pattern="GET" /> | |
</conditions> | |
<action type="Redirect" url="{R:2}" /> | |
</rule> | |
<!-- // SEO rules --> |
Having that lower case rule put an underscore in front of the path part of the URL is very dangerous considering that in ASP.NET MVC it could be getting mapped to a Controller class name. Is there any particular reason you chose to add it?
Also spotted another issue, if sub-domains are in use they can't be browsed to causing 'corrupted content errors' to appear in your browser before it gives up trying to goto the address.
Great. and how would you enforce both www and https??
thank you. thanks for post. My pages tanıtım filmi and web tasarım. asp pages don't see google. these pages are html but I'll do seo with asp.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is great! The action in line 50 should redirect to a url with https as the protocol, not http. But awesome work!