Redirect WWW to Non-WWW using Web.Config in IIS

Use IIS rewrite rule to redirect (301) all www requests to non-www.

commit 9699073 · authored · 1 min read

Redirect WWW to Non-WWW using Web.Config in IIS

Code first, talks later.

<rewrite>
<rules>
<rule name="Redirect to non-www" stopProcessing="true">
<match url="(.*)" negate="false"></match>
<action type="Redirect" url="https://yourdomain.com/{R:1}"></action>
<conditions>
<add input="{HTTP_HOST}" pattern="^yourdomain\.com$" negate="true"></add>
</conditions>
</rule>
</rules>
</rewrite>

Replace the “yourdomain” with your domain name and add it under the system.webServer section in the Web.Config, and that’s it.

Some people prefer www domain and some non-www. I personally prefer www URLs. One important point to remember is never to allow both accessible at the same time. Read my article REDIRECT NON-WWW URLS TO WWW URLS to know why. It will be better if you add the rule on the Web.Release.config with a slight modification. Read more about it on my article INSERTING REWRITE RULE IN RELEASE CONFIG.

local graph · open full graph

"Redirect WWW to Non-WWW using Web.Config in IIS" is connected to the topics Internet Information Services, Search Engine Optimization, Web.config, Rewrite Rules, ASP.NET and related to 6 other entries. Redirect HTTPS requests to HTTP using IIS Rewrite rule in Web.Config Redirect HTTPS requests to … Redirect HTTP to HTTPS using Web.Config in IIS Redirect HTTP to HTTPS usin… Redirect non-www urls to www urls Redirect non-www urls to ww… C# - Get Web.Config Connection String in a Class Library C# - Get Web.Config Connect… IIS - Disable CORS IIS - Disable CORS IIS - OPTIONS Requests Returns 404 IIS - OPTIONS Requests Retu… Internet Information Services #iis Search Engine Optimization #seo Web.config #web-config Rewrite Rules #rewrite-rule ASP.NET #aspnet Redirect WWW to Non-WWW using Web…

comments

loading discussion…