Copied to clipboard

Flag this post as spam?

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


  • Greg Berlin 818 posts 634 karma points
    Jun 29, 2009 @ 10:27
    Greg Berlin
    0

    Using UrlRewriting to redirect domain

    hey all,

    I need to setup some redirections on a website, as follows:

    www.domain1.com/page1.aspx > www.domain2.com/page1.aspx
    www.domain3.com/page2.aspx > www.domain2.com/page2.aspx

    Basically www.domain2.com is the live website, and all other domains should redirect to this one (using 301 permanent redirect for SEO purposes)

    I have discovered that the urlrewriting.net engine is already used by Umbraco, so this is the natural choice of rewriting engines to use.. i'm just wondering if anybody has written a regular expression to do what i need (change the domain name, keep the rest of the url the same)?

    And if that somebody has it setup in a rewrite rule in UrlRewriting.config and can provide the whole rule, that'd be even more supremo.

    Thanks heaps

    Greg

    ps: Site is running Umbraco 3.0.5 - if i upgrade to v4.0, are there any changes required for the rewriting rules?

  • Shannon Deminick 1526 posts 5272 karma points MVP 3x
    Jun 29, 2009 @ 10:47
    Shannon Deminick
    2

    Documentation can be found here:

    http://www.urlrewriting.net/160/en/documentation.html

     

    You'll need to setup a domain redirect such as:

    <add name="asdfasdf"  
               redirect="Domain" 
               ignoreCase="true" rewriteUrlParameter="IncludeQueryStringForRewrite"

    virtualUrl="http://www.domain1.com/(.*)

    destinationUrl="http://www.domain2.com/$1"

     />

    With domain redirects, you need to include the http:// syntax for your Urls.

  • Greg Berlin 818 posts 634 karma points
    Jun 29, 2009 @ 11:05
    Greg Berlin
    0

    Thanks Shannon, but that didn't work for me... i get this error:

    any ideas why?

    Line 34:            ignoreCase="true" rewriteUrlParameter="IncludeQueryStringForRewrite"
    Line 35: virtualUrl="http://www.domain1.com.au/(.*)
    <span style="color: red;">Line 36: destinationUrl="http://www.domain2.com.au/$1"
    </span>Line 37: redirectMode="Permanent"
    Line 38:

  • Greg Berlin 818 posts 634 karma points
    Jun 29, 2009 @ 11:08
    Greg Berlin
    0

    damn... the pasted error looked great in the edit window, but got mangled in the display... anyway, you can still get the idea.

    i noticed in the documentation it says this:

    desitnationUrl

      regular expression replacement term

      A regular expression term describing the target page (physical file)

     

    Does this mean it requires a path to a physical file?  if so, how would i get it to change the actual domain its redirecting to?

  • Shannon Deminick 1526 posts 5272 karma points MVP 3x
    Jun 29, 2009 @ 23:03
    Shannon Deminick
    101

    Doh! sorry, what i posted is missing a closing quotation mark, I had:

    virtualUrl="http://www.domain1.com/(.*)

    originally, but you need:

    virtualUrl="http://www.domain1.com/(.*)"

    This is why your getting a config error.

    No need for physical files to exist, however, are you running IIS 6 or IIS 7? If you are running IIS 6, then you'll also need to add a wildcard mapping to the aspnet isapi DLL. Of the top of my head, you need to go to the home tab for your IIS website, click configuration and in the bottom of the window there's an area that says wildcard mapping. You need to add a reference to aspnet_isapi.dll (or something ... ) from your windows/microsoft.net/(your .net version)... and make sure your set the checkbox correctly so that it doesn't verify that the file exists (otherwise, you would need a real file). IIS 7 doesn't need to use wildcard mappings.

    Hope this helps!

  • Greg Berlin 818 posts 634 karma points
    Jul 01, 2009 @ 13:59
    Greg Berlin
    0

    Thats weird... i fixed the problem almost right away, and came back and said that it was cos of the missing quotation mark.. but that post got lost somehow.  hmmmm... this forum is cool, but definitely still a little quirky.

  • Chief 24 posts 45 karma points
    Sep 23, 2009 @ 08:51
    Chief
    1

    Your example above return a 302 - which is not good ?

    I have succeeded in UrlRewriting.config (/config/UrlRewriting.config) to achieve a clean 301 - Example below:

        <add name="just-a-name-fo-you-know-which-one"  
       redirect="Domain" 
       ignoreCase="true" rewriteUrlParameter="IncludeQueryStringForRewrite"
       virtualUrl="http://www.someothersite.dk/(.*)"
       redirectMode="Permanent"
       destinationUrl="http://www.myrealsite.nu" />

    Cheers!

  • Søren Linaa 255 posts 208 karma points
    Oct 01, 2009 @ 14:46
    Søren Linaa
    2

    Just to sum up so everybody gets it right. All credits goes to the members above.

    This 301 redirect vil make your site go from www.domain.dk/test to domain.dk/test (without www), so the search engines only will crawl one domain and avoid double content.

     

    Edit: UrlRewriting.config (/config/UrlRewriting.config)

    <urlrewritingnet xmlns="http://www.urlrewriting.net/schemas/config/2006/07">
        <rewrites>    
        <add name="Your-name"
       redirect="Domain"
       ignoreCase="true" rewriteUrlParameter="IncludeQueryStringForRewrite"
       virtualUrl="http://www.domain.dk/(.*)"
       redirectMode="Permanent"
       destinationUrl="http://domain.dk/$1" />
        </rewrites>
    </urlrewritingnet>

     

    Cheers !

  • Asger 25 posts 171 karma points
    Jul 27, 2016 @ 10:49
    Asger
    0

    Hi Søren.

    Im trying to deal with the same issue, however im not sure which part of your code i need to fill out with my own data, and with what.

    Could you make that more clear to help me out? :) Basically all i want is that my webpage never uses www in the url.

    Cheers.

  • Ryan 24 posts 106 karma points
    May 03, 2017 @ 00:45
    Ryan
    0

    It took me quite some time to figure out I can only link one domain to another domain, not a route to another domain, for anyone reading...

Please Sign in or register to post replies

Write your reply to:

Draft