Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure Website 301 Redirect - Where Do I Put It?

I want to direct some of my other domains to my primary domain which is hosted at a Windows Azure website.

(For the sake of those that find working with CNAME's and DNS a little "foggy" (like I did) I'm going to layout the details.)

I have the domain www.myDomain.example correctly resolving.

I now want to point www.myOtherDomain.example to www.myDomain.example

At my registrar I have created a CNAME to point
www.myOtherDomain.example to myInternalAzureSite.azurewebsite.net
and then successfully configured it in the in the Azure Website domain manager tool.

Now, when I enter www.myOtherDomain.example into a browser I get the proper web page at www.myDomain.example, however, the address in the browser is still www.myOtherDomain.example not www.myDomain.example as desired.

I understand the two most desirable ways to accomplish this are either:

  1. Forward myOtherDomain.example (which costs $ at some registrars)
  2. Do a 301 permanent redirect

If I have all that correct, I have found many suggestions of HOW to do the 301 redirect, however, I can't seem to figure out WHERE to actually put the redirect?

like image 825
Richard Avatar asked Aug 01 '13 20:08

Richard


People also ask

Where do I put 301 redirects?

Permanently redirect old pages or entire folders of pages to new locations in your Webflow site using the 301 Redirects settings: Open Project settings > Hosting > 301 redirects‍ Add the old URL in the “Old Path” field (eg. /old-url) Add the new URL in the “Redirect to Page” field (/entirely/new-url/structure)

How do I redirect a website from Azure?

Instructions: Create a website in Windows Azure. In the Scale section, select a web site mode of Shared or Standard and save changes. In the Configure section, on the domain names group, add the old domain name (or names) and the new domain name and save changes.

How do you add a redirect?

Redirects allow you to forward the visitors of a specific URL to another page of your website. In Site Tools, you can add redirects by going to Domain > Redirects. Choose the desired domain, fill in the URL you want to redirect to another and add the URL of the new page destination. When ready, click Create.


3 Answers

Windows Azure Websites run IIS. You can use URL rewriting to create rules to rewrite one URL to another.

Instructions:

  1. Create a website in Windows Azure.

  2. In the Scale section, select a web site mode of Shared or Standard and save changes.

  3. In the Configure section, on the domain names group, add the old domain name (or names) and the new domain name and save changes.

  4. In your domain registrar or DNS provider for the old domain and the new domain, change the DNS records to point to the new Windows Azure Website. Use a "CNAME (Alias)" record and point it to the website's domain on Windows Azure, like this: "mywebsite.azurewebsites.net."

  5. Upload your new website's contents to Windows Azure.

  6. In the root of the new website, create a file named Web.config with a contents like this:

     <?xml version="1.0" encoding="utf-8" ?>
     <configuration>
         <system.webServer>
             <rewrite>
                 <rules>
                     <rule name="Redirect old-domain to new-domain" stopProcessing="true">
                         <match url=".*" />
                         <conditions>
                             <add input="{HTTP_HOST}" pattern="^www.old-domain.example$" />
                         </conditions>
                         <action type="Redirect" url="http://www.new-domain.example/{R:0}" redirectType="Permanent" />
                     </rule>
                 </rules>
             </rewrite>
         </system.webServer>
     </configuration>
    
  7. Verify that any request to http://www.old-domain.example/path?query will receive a "301 Moved Permanently" response with a Location header for http://www.new-domain.example/path?query.

For documentation refer to Using the URL Rewrite Module.

For examples refer to Redirect to new domain after rebranding with IIS URL Rewrite Module and IIS URL Rewrite – Redirect multiple domain names to one.

like image 120
Fernando Correia Avatar answered Oct 24 '22 00:10

Fernando Correia


There's no need to upload web.config file as there is one that you can access through the Azure interface.

Open the settings pane for your App Service and click App Service Editor (Preview) in the Development Tools section towards the bottom of the left hand menu.

Click Go to open the Editor in a new tab. You will see the web.config file on the left. Click it to edit in the main pane.

One word of warning - this editor autosaves as you type! I'm sure we'd all do this anyway but I'd recommend preparing your code in an editor and pasting it in.

I was able to add a section without having to manually restart the App Service.

like image 43
TimSmith-Aardwolf Avatar answered Oct 23 '22 23:10

TimSmith-Aardwolf


You can also do the redirect by placing this code in your web.config file under the configuration node:

<configuration>
  <location path="oldpage1.php">
    <system.webServer>
      <httpRedirect enabled="true" destination="http://example.com/newpage1" httpResponseStatus="Permanent" />
    </system.webServer>
  </location>
  <location path="oldpage2.php">
    <system.webServer>
      <httpRedirect enabled="true" destination="http://example.com/newpage2" httpResponseStatus="Permanent" />
    </system.webServer>
  </location>
</configuration>
like image 5
Celt Avatar answered Oct 23 '22 23:10

Celt