Copied to clipboard

Flag this post as spam?

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


  • Neil Hodges 338 posts 987 karma points
    Aug 04, 2016 @ 16:14
    Neil Hodges
    0

    How do i stop people navigating to a page by node Id? i.e. 1109.aspx

    Hi

    From a SEO point of view there are 2 visible routes to the same page.

    /my-page

    and

    /1109.aspx

    They both render the same page? I want only to allow the /my-page to render the page. Is there something i can do to stop the id number of a page from actually rendering a page?

    Crawling a site with an SEO audit flags these up as a bad thing so i would like to get rid of them.

    Or am i missing something? Is this an intended action?

    Thanks for your help in advance. Neil.

  • Nicholas Westby 2054 posts 7100 karma points c-trib
    Aug 04, 2016 @ 16:25
    Nicholas Westby
    0

    I believe those URL's may be used when previewing content. What you could do is detect those URL's in your main layout CSHTML file and redirect away (e.g., to the full URL). However, you would probably want to do that only when you aren't in preview mode: https://our.umbraco.org/forum/umbraco-7/using-umbraco-7/73972-detecting-preview-mode-in-umbraco-7#comment-237079

    Alternatively, you could inject a canonical tag that indicates which URL is the de facto one that should be crawled: https://moz.com/blog/canonical-url-tag-the-most-important-advancement-in-seo-practices-since-sitemaps That has the advantage that it won't adversely affect preview mode.

  • Neil Hodges 338 posts 987 karma points
    Aug 04, 2016 @ 16:42
    Neil Hodges
    0

    Hi

    Ive found this, but it doesnt suggest how to detect if the page being viewed is a preview page.

            @using umbraco
            @using System
            @{var canonicalUrl= String.Empty;}
            @if(umbraco.library.RequestServerVariables ("HTTP_HOST").ToLower().StartsWith("www")) {
                canonicalUrl = string.Concat("http://",  umbraco.library.RequestServerVariables("HTTP_HOST"), Model.Url);
            } else {
                canonicalUrl = string.Concat("http://www.",  umbraco.library.RequestServerVariables("HTTP_HOST"), Model.Url);
            }
            <link rel="canonical" href="@canonicalUrl"  />
    

    How would i firstly detect the preview page, and how would i build up the de facto cononical tag? Instead of Model.Url should i use Model.Name, but how would that work when the url is within a few different sub folders?

    Cheers Neil.

  • Nicholas Westby 2054 posts 7100 karma points c-trib
    Aug 04, 2016 @ 16:45
    Nicholas Westby
    100

    The link from above mentioned how to detect preview mode:

    Umbraco.Web.UmbracoContext.Current.InPreviewMode
    

    However, if you are doing the canonical URL approach, you have no need to detect preview mode. Just get the URL for the page, which should be something like this:

    var canonicalUrl = Model.Content.Url;
    

    I believe that would work in the latest version of Umbraco (7.4.3). Which version are you using?

  • Neil Hodges 338 posts 987 karma points
    Aug 04, 2016 @ 16:51
    Neil Hodges
    0

    Using 4.11.0

    Just checking the output now. my bad!

    it's outputting the de facto cononical tag now :)

    I'll use this approach as it's for the SEO audit guys and think that's all they need it to do.

    Thank you very much for your help!

Please Sign in or register to post replies

Write your reply to:

Draft