Best way of using canonical URLs with XF?

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
 
If you use the xen:link syntax for all forum links then that will ensure correct and consistent links. See your other thread:

http://xenforo.com/community/threads/xen-link-guide.15615/

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

Not so much:

http://www.robotstxt.org/robotstxt.html

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

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.
 
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.
 
Hmm... actually, it does already. See XenForo_ControllerPublic_Category line 28:

PHP:
$this->canonicalizeRequestUrl(
	XenForo_Link::buildPublicLink('categories', $category)
);
 
I should have been clearer. On my site the canonical for all categories shows as:
Code:
<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.
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:
HTML:
<link rel="canonical" href="{xen:link 'canonical:categories', $category}" />
 
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
Code:
<xen:title>{$category.title}</xen:title>

<xen:navigation>
    <xen:breadcrumb source="$nodeBreadCrumbs" />
</xen:navigation>

<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}
    </xen:foreach>
    </ol>
</xen:if>

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.
 
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.
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.
 
Top Bottom