Azure Website 301 Redirect - Where Do I Put It?
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.
Windows Azure Websites run IIS. You can use URL rewriting to create rules to rewrite one URL to another.
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.
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."
Upload your new website's contents to Windows Azure.
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>
Verify that any request to
http://www.old-domain.example/path?query
will receive a "301 Moved Permanently" response with a Location header forhttp://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.