Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Dan 1288 posts 3921 karma points c-trib
    Dec 04, 2009 @ 11:32
    Dan
    1

    How to auto-redirect non-www URLs to www URLs

    Hi,

    Is there a simple way (e.g. in the web.config file or similar) to get all non-www URLs to redirect to their equivalent www URL, or do I need to get my hands dirty with IIS and ISAPI Rewrite?

    Thanks all.

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Dec 04, 2009 @ 13:08
  • Lee 1130 posts 3088 karma points
    Dec 04, 2009 @ 13:16
    Lee
    4

    To be honest I just use ISAPI as I have lots of other bits in it as well - but Chris's solution in that post seems good, thanks for the link Chriztian =)

        <add name="301ReDirect_For_US_Domain"
                   
    redirectMode="Permanent"
                   redirect="Domain"
                   
    ignoreCase="true" rewriteUrlParameter="IncludeQueryStringForRewrite"
       
    virtualUrl="http://www.your-domain.us/(.*)"
       
    destinationUrl="http://www.your-domain.com/$1" />

     

  • BarneyHall 141 posts 210 karma points
    Dec 04, 2009 @ 15:31
    BarneyHall
    0

    Hi Lee, this is actually mercifully easy to do with IIS if you have access to it.
    http://www.mcanerin.com/EN/articles/301-redirect-IIS.asp (see the redirecting an individual page)

    Barney

  • Lee 1130 posts 3088 karma points
    Dec 05, 2009 @ 17:36
    Lee
    0

    Much easier with ISAPI dude, and all the other redirects are in one file as well.. https to http.. Upper case to lower case etc.. etc..  Also using that method you have to have two entries in IIS which is a pain when you have lots of sites running.

  • ianhoughton 281 posts 605 karma points c-trib
    Oct 05, 2010 @ 00:38
    ianhoughton
    0

    Lee, do you have an example of using urlrewritingnet to change from upper case to lower case ?

  • Joel 3 posts 23 karma points
    Jul 12, 2011 @ 05:56
    Joel
    0

    Hi there.

    I have added the script to the UrlRewriting.config, and all works fine except when I type in the URL without the www instead of going to the site like www.test.com it goes to www.test.com/default.aspx

    Is there a way I can make it so it doesn't go to /default.aspx?

    Thanks,

    Joel

  • Rich Green 2246 posts 4008 karma points
    Jul 12, 2011 @ 09:43
    Rich Green
    0

    There was a nice post somewhere with the rewrites so you didn't have to hardcode the domain name, I'll see if I can dig it out.

    Rich

  • Joel 3 posts 23 karma points
    Jul 12, 2011 @ 09:45
    Joel
    0

    If you could find that post it would mean so much.

    Thanks

  • Rich Green 2246 posts 4008 karma points
    Jul 12, 2011 @ 09:52
    Rich Green
    0

    Post is here 

    http://umbraco.miketaylor.eu/2010/11/03/url-rewriting-and-seo/

    Pretty sure the final answer is here

    http://snipt.org/okppn/

    <rule name="Canonical host name" stopProcessing="true">
        <match url=".*" />
        <conditions>
            <add input="{HTTP_HOST}" pattern="^(?!www\.)(.*)" />
        </conditions>
        <action type="Redirect" url="http://www.{C:1}/{R:0}" />
    </rule>

    Rich

     

  • Joel 3 posts 23 karma points
    Jul 13, 2011 @ 04:06
    Joel
    0

    Great.

    Thank you very much for you help

  • Brian 7 posts 27 karma points
    Jan 10, 2013 @ 16:05
    Brian
    0

    I had issues with the solutions above.  The following worked for me in Umbraco 4.9.1 - In the UrlRewriting.config, use this:

    <add name="forcewww" virtualUrl="http\://(?!www\.)" redirectMode="Temporary" destinationUrl="http://www." ignoreCase="true" redirect="Domain" />

    This also carries through any querystring parameters that might have been in the original request.  Depending on your needs, you might prefer to set the redirectMode to Permanent.  Happy coding!

Please Sign in or register to post replies

Write your reply to:

Draft