Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirecting non-WWW to WWW in an Azure Website

Tags:

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?

like image 608
RBT Avatar asked Mar 03 '14 08:03

RBT


People also ask

How do I redirect a non-www domain to www?

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 .

How do I redirect a non-www Azure?

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.

How do I redirect www to non-www in web config?

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.

Do I need to redirect to non-www?

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)


2 Answers

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> 
like image 170
G Ravinder Avatar answered Sep 20 '22 05:09

G Ravinder


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:

  1. Using the forwarding feature offered by GoDaddy (you can find it in the GoDaddy dashboard (domain details page). In this way you can point example.com to a GoDaddy IP that responds with a redirection to www.example.com
  2. Write some code in ASP.NET that detects when the address is missing "www." and then redirecting to 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:

  1. Get the virtual IP address associated to your Azure website: from the Azure management portal click on your website, go to the dashboard section and click Manage Domains. You should get something like "The IP address to use when you configure A records: xxx.xxx.xxx.xxx".
  2. Go to GoDaddy and set an A record with "Host" to @ and "Points to" set to the IP found at step 1
  3. Add a CNAME record with "Host" set to awverify and "Points to" set to the address of your azure website prefixed with awverify (for example awverify.mywebsite.azurewebsites.net)
  4. Add a CNAME record with "Host" set to www and "Points to" set to the address of your azure website (for example mywebsite.azurewebsites.net)
  5. Save the zone file in GoDaddy
  6. Go back to windows azure in the "Manage Domains" section of your website and add both 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/

like image 23
Andrea Coluccio Avatar answered Sep 23 '22 05:09

Andrea Coluccio