How To Redirect WWW. To The Root of Your Application With IIS



Last updated: January 28th, 2024

Redirecting All Sub-Domains

The first step to redirect a www. sub-domain to the root so that it always resolves to just the domain is to download the IIS Manager. This is assuming you do not have direct access to the server and are using Windows as your server. After this, the account that is going to access IIS needs premission granted. After logging in, go the the globe icon under the connections section and select: Connect a Site. After this I put in my Server name and Site name as my domain name and click Next. Then I authenticate with my username and password to the account and click next and after it connects, Finish.

From here I go into the Feature View of the IIS control panel and select URL Rewrite. Next I will click on the Action: Add Rule(s) and select: Canonical Domain. A list of options are provided to me and I will select: mouthguardstore.com. This default pattern is good for redirecting all sub-domains to the root.

Limiting Redirects To Only WWW.

The default pattern does not allow for other sub-domains which I have, such as: http://snoring-and-sleep-apnea.mouthguardstore.com/. I don't want that to redirect to the root of the application because those are actual pages. I'll have to edit the rule that was created and change it to: Check if input string: Matches the Pattern (to prevent an infinite loop) and then set the pattern from: ^.mouthguardstore\.com$ to ^www.mouthguardstore\.com$ so that it redirects all www. prefixed URLs to their non-www. counter part. Now I have consolidated all the URLs so that only one document exists for the content requested in a www. or non-www situation.


Comments

No Comments

Post Comment

Prove you are human 2 + 4 =

Tagged: IIS


Join my email list!



ryan
About Me

With 15 years in tech, I've excelled as a senior software engineer, specializing in ASP.NET, C#, SQL, Azure, and front-end technologies. I've led diverse projects across various sectors, from startups to global corporations, particularly during my decade in the San Francisco Bay Area.


Sign Up With SoftSys Hosting! (My host)