iis | seo | web-config | rewrite-rule | aspnet

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

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

Abhith RajanSeptember 19, 2017 · 1 min read · Last Updated:

Code first, talks later.

1<rewrite>
2 <rules>
3 <rule name="Redirect to non-www" stopProcessing="true">
4 <match url="(.*)" negate="false"></match>
5 <action type="Redirect" url="https://yourdomain.com/{R:1}"></action>
6 <conditions>
7 <add input="{HTTP_HOST}" pattern="^yourdomain\.com$" negate="true"></add>
8 </conditions>
9 </rule>
10 </rules>
11</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.

Written by Abhith Rajan
Abhith Rajan is an aspiring software engineer with more than 8 years of experience and proven successful track record of delivering technology-based products and services.
Buy me a coffee

Was this helpful?

👈 This is a live react editor.

This page is open source. Noticed a typo? Or something unclear?
Improve this page on GitHub

Related ArticlesView All

Related StoriesView All

Related Tools & ServicesView All

woorank.com

Website Review Tool & SEO Checker

Instantly review your website for free with the WooRank SEO Checker! Find issues, track keywords, identify opportunities & create reports. 14 day Free Trial.
seobility.net

SEO Checker | Test your website for free with Seobility

Instantly review your website for free with the SEO checker from Seobility and get tips for a better search engine optimization and higher rankings.