I have a domain with Godaddy, and a website on the Azure websites infrastructure. What I want to achieve is to use only the www version of my domain. If a user enters "example.com" in their browser I want them to be redirected to "www.example.com".
The site is hosting a ASP.Net MVC 5 app if that makes a difference. How do I configure this?
The easiest way of redirecting a non-www URL to www is to place a rule in the . htaccess file. You can do so via FTP, SSH, or your hosting account's control panel. hPanel users can easily access and edit the .
To make it a secure connection the redirect function URL — http://redirect.azurewebsites.net — should have an SSL certificate. You could add one from Azure Portal, in the TLS/SSL binding section of the Function App menu.
Use IIS rewrite rule to redirect (301) all www requests to non-www. Code first, talks later. Replace the “yourdomain” with your domain name and add it under the system. webServer section in the Web.
For example, if you've chosen to use non-www URLs as the canonical type, you should redirect all www URLs to their equivalent URL without the www. Example: A server receives a request for http://www.example.org/whaddup (when the canonical domain is example.org)
add this code this code under <system.webServer>
section
<rewrite> <rules> <rule name="Redirect to www"> <match url=".*" /> <conditions logicalGrouping="MatchAny"> <add input="{HTTP_HOST}" pattern="^(www\.)(.*)$" negate="true" /> </conditions> <action type="Redirect" url="http://www.{HTTP_HOST}/{R:0}" redirectType="Permanent"/> </rule> </rules> </rewrite>
If you want a REAL redirection (i.e. when a user types example.com
then the address in the browser automatically changes to www.example.com
) then you have two options:
example.com
to a GoDaddy IP that responds with a redirection to www.example.com
www.example.com
However, if you just want the users that type example.com
to get the same content as users typing www.example.com
and you don't mind people seeing example.com
without www in their address bar, then proceed as following:
@
and "Points to" set to the IP found at step 1awverify
and "Points to" set to the address of your azure website prefixed with awverify
(for example awverify.mywebsite.azurewebsites.net
)www
and "Points to" set to the address of your azure website (for example mywebsite.azurewebsites.net
)example.com
and www.example.com
to the list of domain names. If you get any error at step 6, just wait some hours to let the DNS changes to propagate and retry.
More info here: https://www.windowsazure.com/en-us/documentation/articles/web-sites-custom-domain-name/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With