Redirect All Non-WWW Requests to WWW in ASP.NET Core 6 MVC

 
Written by Mark Pringle |
Published on:

For SEO and Google indexing purposes, you should have a consistent URL to access. For instance, if you can access your website via https://www.learnaspnet.com/ and https://learnaspnet.com/ (notice the missing www), that will present problems.

Traditionally, the "Word Wide Web" prefix, www, has referred to websites that are accessible online. Regarding web standards, although the difference may seem inconsequential, https://www.learnaspnet.com takes you to a totally different location than https://learnaspnet.com. Probably, more importantly, Google treats these as two different websites from an SEO perspective, thus diluting the power of your search engine optimization. 

It is best that users and Google only access one of these URLs.

To redirect all non-www requests to www in ASP.NET Core 6 MVC, add the following to your Program.cs file.

app.UseRewriter(new RewriteOptions()
   .AddRedirectToWww()
);

Remember that today's browsers may hide the www part of the website's URL in the search bar. Don't be fooled! It is still there; it's just not visible. Don't let this impact your decision.

Copyright © TravelDailyLife.com

Author: Mark Pringle
I'm just a guy who is addicted to the unfamiliar and who fulfills this addiction by traveling and writing about my travels. As a lover of sports, penning opinion articles related to sports is also a pastime.
My External Website (External Website Opens in New Window)

Comments

Please Login to Comment
No comments have been posted. Be the first.



Hire a Writer