Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2010-05-25 09:19:25

beechy
Member
Registered: 2006-03-02
Posts: 92

canonical url and /section - /section/article-title

I am currently using the code here:

http://txptips.com/dynamic-canonical-urls

to produce canonical-urls. This works nicely on the,

  • Homepage
  • Section page
  • article page

However the article that appears at /about also appears at – /about/about and the canonical tags appear as follows;

<link rel="canonical" href="/about" />
<link rel="canonical" href="/about/about" />

I dont want to have to manually setup a .htacess redirect for /about/about to redirect to /about, is there anyway of making the canonical-urls the same for both of these.

I know I could do something like

<txp:if_article_id id=" id of about article ">
<link rel="canonical" href="<txp:site_url />about" />
<txp:else/>
<txp:if_individual_article>
   <link rel="canonical" href="<txp:permlink />" />
<txp:else />
<txp:if_section name="">
   <link rel="canonical" href="<txp:site_url />" />
<txp:else/>
<link rel="canonical" href="<txp:site_url /><txp:section />" />
</txp:if_section>
</txp:if_individual_article>
</txp:if_article_id>

But this would mean manually adding the article id for the first article in each section.

Does anyone have a better solution.

Last edited by beechy (2010-05-25 09:19:49)

Offline

#2 2010-05-25 17:03:45

thebombsite
Archived Plugin Author
From: Exmouth, England
Registered: 2004-08-24
Posts: 3,251
Website

Re: canonical url and /section - /section/article-title

I am currently using this to do something similar:-

<txp:if_individual_article>
<txp:if_section name="about,contact,privacy,resume">
<link rel="canonical" href="<txp:site_url /><txp:section />" />
<txp:else />
<link rel="canonical" href="<txp:permlink />" />
</txp:if_section>
<txp:else />
<txp:if_section name="tag">
<link rel="canonical" href="<txp:site_url />tag/<txp:tru_tags_tag_parameter />" />
<txp:else />
<txp:if_section name=",default">
<link rel="canonical" href="<txp:site_url />" />
<txp:else />
<link rel="canonical" href="<txp:site_url /><txp:section />" />
</txp:if_section>
</txp:if_section>
</txp:if_individual_article>

which also includes conditionals for the default section and tag section (which I have). By using the <txp:if_section> tag you can just use a comma-separated section list rather than have to enter article ids. Is that what you mean?

Last edited by thebombsite (2010-05-25 17:05:38)


Stuart

In a Time of Universal Deceit
Telling the Truth is Revolutionary.

Offline

Board footer

Powered by FluxBB