Copied to clipboard

Flag this post as spam?

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


  • Ben Blohowiak 2 posts 72 karma points
    Aug 22, 2016 @ 12:45
    Ben Blohowiak
    0

    Redirects for Newbie

    I'd like to make it so that the URLs "http://www.domain.org/foo" and "http://www.domain.org/bar" each redirect to different locations and are not themselves pages. (I don't want "foo" and "bar" to automatically appear in the header menu of the website.)

    I am very new to Umbraco so please assume I know little to nothing. Thank you for the help!

  • Marc Goodson 2157 posts 14434 karma points MVP 9x c-trib
    Aug 23, 2016 @ 09:14
    Marc Goodson
    2

    Hi Ben

    What kind of redirect do you want the Urls to make ?

    a) 301 permanent redirect b) 302 temporary redirect

    or c) is it just ok if that the foo and bar urls returns the appropriate page from Umbraco ?

    This info would dictate what is the best approach.

    So for example in the scenario of c) you can use a special 'hidden feature' of Umbraco called UrlAlias - if you create a textbox on your Umbraco document type and name it's alias specifically:

    umbracoUrlAlias

    then you can specify here a comma delimited list of alternative urls the page should also be loaded under.

    https://our.umbraco.org/wiki/reference/umbraco-best-practices/umbracourlalias/

    But this isn't a redirect, the request code will be 200, this might upset you if you are SEO aware.


    If you create a checkbox on your document types called 'umbracoNaviHide' then you can exclude your redirect pages from navigation.

    https://our.umbraco.org/wiki/reference/umbraco-best-practices/umbraconavihide/

    so with b)

    if you create a 'Redirect Page' document type add a textbox called umbracoRedirect or a content picker called umbracoInternalRedirectId, then if either of these properties are filled in, Umbraco will create a temporary 302 redirect from the url of your Redirect Page to your target content.

    but really you probably want a 301 redirect.

    Here we have nothing 'out of the box' (except in 7.5 the automatic tracking and creating of 301 redirects when pages are moved or renamed, but at this moment we can't easily manually create redirects here)

    There are plenty of packages that would deliver this functionality for you:

    https://our.umbraco.org/projects/developer-tools/301-url-tracker/

    Alternatively, simplistically if on your Redirect Page you create a textbox called 'umbracoExternalRedirect' and then a 'RedirectPage' template and in the template you put:

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
        @{
        Layout = null;
        }
    @if (Model.Content.HasProperty("umbracoExternalRedirect") && Model.Content.HasValue("umbracoExternalRedirect")) {
            var redirectUrl = Model.Content.GetPropertyValue<string>("umbracoExternalRedirect");
            Response.RedirectPermanent(redirectUrl);
    }
    

    Publishing this page will create a 301 redirect for the url of your Redirect Page to your target Url.

    If you have lots of redirects, you might not want to create them in the root of your site, so to aid management of these simple redirects, create a RedirectFolder document type as a list view, and create your Redirect Pages under here.... but my urls will then be /Redirects/NameOfRedirect and I want them to be /foo - with this approach to achieve that you would use the first trick of using umbracoUrlAlias, to enable your redirect page at /redirect/foo to actually be requested as /foo, and then the template would 301 redirect to what was filled into your umbracoExternalRedirect page.

    regards

    Marc

  • Ben Blohowiak 2 posts 72 karma points
    Aug 23, 2016 @ 14:51
    Ben Blohowiak
    0

    Thank you, that was very helpful!

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies