I am trying to redirect from website from https://www.example.com to https://example.com in ASP.NET MVC 5, but I am not able to do it, I am getting this error, when navigating to https://www.example.com
HTTP Error 404. The requested resource is not found.
I have tried to use the solution provided here
https://stackoverflow.com/a/3197446/3559462
https://stackoverflow.com/a/2178381/3559462
Currently my Web.Config has this code for url re-write
<rule name="Redirect everything to https://example.com" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTP_HOST}" pattern="example.com" negate="true" />
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://example.com/{R:0}" />
</rule>
What is missing? It use to work previously but not now, why I am getting 404 suddenly and how to re-direct https://www.example.com to https://example.com without getting any error.
Do I need to register any DNS settings in my GoDaddy account? Or C#/web.config code can solve this error.
EDIT: when trying to use url https://example.com it works, here is the request/response headers image