1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Best way of using canonical URLs with XF?

Discussion in 'XenForo Questions and Support' started by Ryan Kent, May 21, 2011.

  1. Ryan Kent

    Ryan Kent Well-Known Member

    I have since realized my use of URLs has been inconsistent. XF adds a slash to the end of all URL links. I have been omitting them whenever I created a link. Also there is the many uses of parameters such as styles and sort orders in URLs.

    I have learned several methods which can help, but I wanted to ask which is best? Is there a simple way to tell all robots to only use the URL in the format with an ending slash, and to disregard any of the extra URLs with parameters such as ?style= or ?sort
  2. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    If you use the xen:link syntax for all forum links then that will ensure correct and consistent links. See your other thread:


    Not so much:


    Is there a reason why you want to explicitly block those forum locations? This seems like another pointless exercise. ;)
    Forsaken and Kier like this.
  3. Kier

    Kier XenForo Developer Staff Member

    Jake is right, always use the {xen:link ...} system when liking to XenForo pages within templates.
  4. Ryan Kent

    Ryan Kent Well-Known Member

    I am trying to learn and do the right thing. I have spent my last couple months reading what's available on the web, and I have recently learned a lot of it is incorrect information. I signed up @ SEOmoz for their 30 day trial and I am learning a ton. I really hope the information is accurate this time, but it very much seems to be. They refer to a lot of Google videos hosted by Matt Cutts.

    I have been reviewing my crawl report and I see a single URL listed many times and being flagged as duplicate content. Usually it is one page with either different style id parameters, or different sort orders. I want to clean things up and say to the crawl report / search engine "hey, ignore all those ?styleid= and ?sortby parameters and just use the basic URL".

    I have seen how XF explicitly canonicalizes threads with <link rel="canonical" which is great. On my site I use Category pages and XF does not offer canonicals for them and my crawl report is full of them being listed.

    Basically I am just looking for the best way to clean up my site. I made a ton of mistakes in the past. I went through and fixed most of them. This is what's left.
  5. Kier

    Kier XenForo Developer Staff Member

    I will add canonicalization for category pages to 1.0.2, as it's a very simple thing to add, and should really have been there from the outset.
    Oracle likes this.
  6. Kier

    Kier XenForo Developer Staff Member

    Hmm... actually, it does already. See XenForo_ControllerPublic_Category line 28:

  7. Kier

    Kier XenForo Developer Staff Member

    However the category template does not include rel canonical, so I will add that now.
  8. Ryan Kent

    Ryan Kent Well-Known Member

    I should have been clearer. On my site the canonical for all categories shows as:
    <link rel="canonical" href="http://www.terapvp.com/threads/" />
    Link to a category on my site: http://www.terapvp.com/categories/tera-forums-by-region.21/

    My ACP > Options > Nodes & Forum List > Create Pages for Categories box is checked.
  9. Kier

    Kier XenForo Developer Staff Member

    There is something very wrong with your category_view template if it's showing that as your canonical URL.

    It looks like you've taken the canonical tag for thread_view and put it into category_view, which would do horrible things.

    The canonical tag for category_view should look like this:
    <link rel="canonical" href="{xen:link 'canonical:categories', $category}" />
    Oracle likes this.
  10. Ryan Kent

    Ryan Kent Well-Known Member

    Ok. Once again I failed to be clear and sorry if I have wasted your time. My last attempt.

    I reverted the template. Below is the 100% default XF category_view template code
        <xen:breadcrumb source="$nodeBreadCrumbs" />
    <xen:container var="$quickNavSelected">node-{$category.node_id}</xen:container>
    <xen:if is="{$renderedNodes}">
        <ol class="nodeList section sectionMain">
        <xen:foreach loop="$renderedNodes" value="$node">
            {xen:raw $node}
    To the best of my understanding there is no code related to providing a canonical link. I was trying to build my own link in the category_view template and make it work using the forum code as a guide.
  11. Ryan Kent

    Ryan Kent Well-Known Member

    All working perfectly now, thx for the guidance.
  12. Kier

    Kier XenForo Developer Staff Member

    Kinda... the code I provided above is the PHP that forces the browser to 301 redirect if the URL that is hit is non-canonical.

Share This Page