find a location for property in a new city

Monday, 21 November 2011

Two host names appearing on Google for the same site

If you have an application hosted in Window's Azure your application will have a host name such as mysite.cloudapp.net. You will probably also have a CNAME that points www.mysite.com to the cloudapp. So what if both domains have been indexed by Google? How do you get cloudapp.net URL off of Google?

This is not a problem with Windows Azure; this can happen to any site that has two hostnames/IPs that point to the same site. It is just a recurring issue I see during my Azure consultancy work and worth a quick explanation and solution.

Both mysite.cloudapp.net and mysite.com are pointing to the exact same application and servers so there is no way you can switch one off since they are one and the same, just accessible through two paths. (Well, more than two since they will at least have IP address paths too.)

This issue can be solved in your application code. Your application will need to determine what host name the application has been accessed through and either display the page if the host name is correct or 301 redirect to the correct hostname if the host name is wrong. So how to do it?

301 Redirect cloudapp.net to your correct domain

This can be done in your application by setting a redirect rule using the IIS URL Rewrite Module. There is already a template in IIS's Rewrite Module for doing this called "Canonical domain name" under the SEO section, however I don't particularly like this one since it redirects everything that isn't the correct hostname (e.g. your development machine). Still, you should have a look at it to see what it is doing.

The key steps of what your rule should be doing are:

  1. Check to see if the host name is incorrect
  2. If it is it should issue a redirect to the correct domain name
  3. The redirect should be a 301
  4. The page should remain e.g. http://mysite.cloudapp.net/hello.html -> http://www.mysite.com/hello.html
  5. If the host name is not in violation the page rendering should continue without further action

So you can make your own however you feel is best but here is my example to get you going.

<rewrite>
    <rules>
        <rule name="CanonicalHostNameRule1">
            <match url="(.*)" />
            <conditions>
                <add input="{HTTP_HOST}" pattern="^mysite\.cloudapp\.net$" negate="false" />
            </conditions>
            <action type="Redirect" url="http://www.mysite.com/{R:1}" />
        </rule>
    </rules>
</rewrite>

This code goes in the <system.webServer>...</system.webServer> section of your web.config. Again this is only an example, you may wish to add another condition for handling your IP address for example.

This redirect will solve the problem of any users visiting the incorrect site. Also, because it is a 301 redirect, over a week or two Google will remove the cloudapp.net URL from its search results and attribute its existing value to the correct URL.

Follow britishdev on Twitter

30 comments:

  1. Thank you so much for sharing! This is what I need to find.
    pictaram

    ReplyDelete
  2. Your article gives me another approach on the subject.
    adultwork

    ReplyDelete
  3. No worries, Pointing two URLs to the same website is a good way to direct traffic to your site from several different domain names.For more details visit, Do my excel homework

    ReplyDelete
  4. Nice post! This is a very nice blog that I will definitively come back to more times this year! Thanks for informative post.

    CatNinja.org
    Wormateio

    ReplyDelete
  5. Wholesale printed custom perfume boxes with the highest quality and affordable prices. Free worldwide Delivery and free Custom Perfume Boxes design.

    ReplyDelete
  6. Buy online wholesale custom eyeshadow palette packaging and packaging at seashore packaging at the easy price Free shipping worldwide with 24/7 customer support.

    ReplyDelete
  7. Buy online wholesale printed candle boxes and packaging at easy prices and shipping worldwide, with 24/7 customer support. Get a free custom quote now!!

    ReplyDelete
  8. Blackbird packaging provide you with any size, shape design, cbd boxes sooner than any other packaging competitor in the market

    ReplyDelete
  9. Blackbird packaging provide you with any size, shape design, cookie boxes wholesale sooner than any other packaging competitor in the market

    ReplyDelete
  10. Packaging town is a one stop solution for the short-run tincture packaging needs and supplies. At affordable prices. Request a free quote now.

    ReplyDelete
  11. Blackbird packaging provide you with any size, shape design, custom wholesale cookie boxes sooner than any other packaging competitor in the market

    ReplyDelete
  12. article is good but you can use oscola referencing tool for better understanding.

    ReplyDelete
  13. why my host name does not appear on google. Host name is online assignment provider

    ReplyDelete
  14. Packaging town is a one stop solution for the short-run tincture packaging needs and supplies. At affordable prices. Request a free quote now.

    ReplyDelete
  15. Pacakaging town is a one stop solution for the short-run custom apparel boxes needs and supplies. At affordable prices. Request a free quote now.

    ReplyDelete
  16. Packaging town is a one stop solution for the short-run custom soap boxes needs and supplies. At affordable prices. Request a free quote now.

    ReplyDelete
  17. Buy fashionable men's sweatshirts at Wild Goat. Shop the Latest Collection of Men's Summer and Winter Sweatshirts in Pakistan. Exclusive collection of Men's sweatshirts are available at Wild Goat. Shop the best quality and finest fabrics from Wild Goat. Style a classy look in Wild Goat's finest sweatshirts.

    ReplyDelete
  18. buy electronics online from alfatah at best prices. Get free shipping

    ReplyDelete
  19. buy zipper hoodie online for men from wild goat clothing at best pricces. Get Free shipping

    ReplyDelete
  20. Blackbird packaging provide you with any size, shape design, bath bomb packaging sooner than any other packaging competitor in the market

    ReplyDelete
  21. Blackbird packaging provide you with any size, shape design, sleeve boxes wholesale sooner than any other packaging competitor in the market

    ReplyDelete
  22. Blackbird packaging provide you with any size, shape design, cookie packaging boxes sooner than any other packaging competitor in the market

    ReplyDelete
  23. the person who create this post it was a great human..thanks for shared this
    If you are having trouble in drafting your assignments, it’s time to consider moving towards assignment help online services.
    ozpaperhelp.com is here to help you with the best of online writing services which can help you submit your assignment on time.
    they have the best team to assist with your needs of assignment help online services and that too at very affordable rates.

    Taxation Theory Practice Law Assignment Help Uk
    Management Consulting Assignment Help
    Chemical Engineering Assignment Help
    Statistics Assignment Help
    SAS Assignment Help By SAS Experts
    CDR Engineers Australia
    CDR Report Writers
    Marketing Coursework Help
    MBA Essay Help
    Voice Thread Assignment Help
    Practical Analysis Assignment Help
    Memo Assignment Help
    Flowchart Assignment Help
    TCP/IP Networking Assignment Help
    SAGE Assignment Help
    Cryptography Assignment Help
    Cyber Security Assignment Help
    ASP Assignment Help
    DATA Flow Diagrams Assignment Help
    Physician Assignment Help

    ReplyDelete
  24. This Development company developed many websites. Don't worry! If hosting name appear on google with same name, This is beneficial for hosting company. There are many companies that provides the hosting services.
    If your are worry about house roof and you want solve this problem, then you should hire Roofer Service Centennial for best services.

    ReplyDelete
  25. This post is very informative. You discuss all the key point like Check to see if the host name is incorrect, If it is it should issue a redirect to the correct domain name and The redirect should be a 301.
    automotive locksmith Dallas provide best locksmith services. This company provide Commercial Locksmith services and Broken Key Extraction services.

    ReplyDelete
  26. Buy jogger pants pakistan from ndure at best prices delivered at your doorstep. Get free shipping

    ReplyDelete
  27. When you need to repair, replacement, new system installation, or kept maintenance for your indoor and outdoor Heating systems, you can rely on Lock repair services in Jacksonville FL expert team to get the job done quickly and efficiently.

    ReplyDelete
  28. Thank you for this informative blog. For futher information 4k ota visit our website.

    ReplyDelete