Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
528 views
in Technique[技术] by (71.8m points)

asp.net - 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.com correctly resolving.

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

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

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

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

  1. Forward myOtherDomain.com (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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.com$" />
                        </conditions>
                        <action type="Redirect" url="http://www.new-domain.com/{R:0}" redirectType="Permanent" />
                    </rule>              
                </rules>
            </rewrite>
        </system.webServer>
    </configuration>
    
  7. Verify that any request to "http://www.old-domain.com/path?query" will receive a "301 Moved Permanently" response with a Location header for "http://www.new-domain.com/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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...