Copied to clipboard

Flag this post as spam?

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


  • BarneyHall 141 posts 210 karma points
    Nov 11, 2009 @ 10:44
    BarneyHall
    0

    301 redirect options

    Hello, can anyone offer any advice on how to best implement 301 redirects?

    There seems to be a few options, but I wondered what is best practise and most practical?

    Ideally a solution within the Umbraco UI (4.0.2.1) is prefered in this case.

    Any pointers and advice greatly appreciated.

    Thank you,
    Barney

  • Bogdan 250 posts 427 karma points
    Nov 11, 2009 @ 11:20
    Bogdan
    1

    I don't know about best practice, but you can use an umbracoRedirect property, or from xslt with a C# script, e.g.

      <msxsl:script language="C#" implements-prefix="redir">
        <msxml:assembly name="System.Web" />
        <msxml:using namespace="System.Web" />
        <![CDATA[
        public String Redirect(String url){
             System.Web.HttpContext.Current.Response.Status = "301 Moved Permanently";
             System.Web.HttpContext.Current.Response.AddHeader("Location", url.ToString());
             return "";
        }
        ]]>
      </msxsl:script>

    Hope this helps.

  • BarneyHall 141 posts 210 karma points
    Nov 11, 2009 @ 12:17
    BarneyHall
    0

    Hey thanks for your response - really appreciate the help.

    Out of interest is the umbracoRedirect making a 301 redirect?

    If so this is cool for one or two pages, but looks like updating the UrlRewriting.config might be better for a number fo pages - though the client can't do this through the UI as far as I can tell?

  • dandrayne 1138 posts 2262 karma points
    Nov 11, 2009 @ 12:20
    dandrayne
    0

    umbracoRedirect is a 302, so best taking bfi's code and turning it in to a macro that goes in each page, along with a property that allows setting a redirect url.  If the redirect is set, call the macro and pass in the url to redirect to.  You can see another example of inline c# and calling a function from within xslt at http://our.umbraco.org/projects/change-output/general/4246-Also-possible-using-inline-script-in-xslt

    Dan

  • Bogdan 250 posts 427 karma points
    Nov 11, 2009 @ 12:32
    Bogdan
    0

    I've just checked a page with umbracoRedirect in firebug and the http response status is 302 Found.

  • BarneyHall 141 posts 210 karma points
    Nov 11, 2009 @ 12:43
    BarneyHall
    0

    Thanks for your help chaps.

  • Rasmus Berntsen 215 posts 253 karma points c-trib
    Nov 11, 2009 @ 14:10
    Rasmus Berntsen
    0

    You could also install the URL Rewrite module for IIS and add your 301's to the Web.Config:

            <rewrite>
                <rules>
                    <rule name="Redirect non-www to www" stopProcessing="true">
                        <match url=".*" />
                        <conditions>
                            <add input="{HTTP_HOST}" pattern="^CHANGE-MY-DOMAIN.TLD$" />
                        </conditions>
                        <action type="Redirect" url="http://www.CHANGE-MY-DOMAIN.TLD" redirectType="Permanent" />
                    </rule>
                </rules>
            </rewrite>

    That's usually what we do... :)

  • Casey Neehouse 1339 posts 483 karma points MVP 2x admin
    Nov 12, 2009 @ 08:51
    Casey Neehouse
    0

    I wrote a simple user control that checks an xml file of old paths and redirects to new paths/id.  This can be added to a 404 page in umbraco, and is written to work with both non-ASPX pages, as well as umbraco 404 errors.  (only works on 404 requests).

    As for domain redirects (and even cononical issues), a control that checks for a specific domain could be used to provide those options.  I have one that checks the domain against a property on my root node and redirects the request to that domain if it does not match.  It also checks that the page path is an exact match of the NiceUrl generated URL (with some exceptions).  This guarantees that search engines only get one instance of a page versus all the variations that may occur due to link changing..

    Email me at casey at bestcasetech.com if you would like the controls.

  • Claushingebjerg 936 posts 2571 karma points
    Nov 19, 2009 @ 17:34
    Claushingebjerg
    0

    I'm building a new version of an old htm site, that is very fragmented

    So making a list of existing pages and their new counterpart,for use in urlrewrite.config in umbraco, is a pretty daunting task.

    So i thought it would be easier if my client could input the url of the old page when creating the new page, and thereby tell umbraco that if for example

    /credits/credits.htm is requested, it would redirect to /hello/credits.aspx

    Is there a simple way to do this?

     

     

  • Chris Houston 535 posts 980 karma points MVP admin c-trib
    Nov 19, 2009 @ 23:17
    Chris Houston
    1

    Hi All,

    You can also use the built in URL rewriting.net that comes packaged with Umbraco.

    As BarneyHall mentioned above by default you cannot edit the config files through the UI, but, if you look in the packages section you can find a package that adds admin of the config files to the UI.

    I've just posted the same example on another post, but I thought it was clearer if I cross posted it here, I hope that's ok?!

    You can then add 301 ( or 302 ) re-directs, here is an example of a 301 re-direct:

        <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" />

    And you can see this working if you open up firebug and look at the network section and then hit the following URL, as I have just updated my redirect using this.

    http://www.nursingpersonnel.co.uk

    Should 301 re-direct to:

    http://www.nursing-personnel.co.uk

    Cheers,

    Chris

  • Chris Houston 535 posts 980 karma points MVP admin c-trib
    Nov 20, 2009 @ 00:09
    Chris Houston
    3

    I have just added a blog post about how to add intellisense to Visual Studio when editing the urlrewriting.config file, it's not something I realised you could do until today, so I thought it might be useful for someone reading this thread :)

    Adding Intellisense for editing the urlrewriting.config file

    Cheers,

    Chris

  • Kyle Skrinak 272 posts 327 karma points
    Apr 11, 2011 @ 16:31
    Kyle Skrinak
    0

    Umbraco 4.6.1: Confused. I've made the above change (tailored to my situation, of course) to conf/urlrewriting.conf, and I've used the config tree package, ensuring that I'm modifying against my live site. But the change isn't happening.

    One difference between the example and my use case is I don't need to switch domains; I'm redirecting within the app. For example:

    <urlrewritingnet xmlns="http://www.urlrewriting.net/schemas/config/2006/07">

      <rewrites>
        <add name="301_Redirects_for_Articles"
             redirectMode="Permanent"
             redirect="Domain"
             ignoreCase="true"
             rewriteUrlParameter="IncludeQueryStringForRewrite"
             virtualUrl="http://customsite.com/articles/articles/(.*)"
             destinationUrl="http://customsite.com/articles/$1" />
      </rewrites>

    </urlrewritingnet>

    What's the best way to troubleshoot this?

Please Sign in or register to post replies

Write your reply to:

Draft