[MODDB] Canonical URL

A place for MOD Authors to post and receive feedback on MODs still in development. No MODs within this forum should be used within a live environment!
Ideas Centre
User avatar
soumik
Registered User
Posts: 486
Joined: Tue Nov 06, 2007 7:27 pm
Contact:

[MODDB] Canonical URL

Post by soumik »

Modification Name: Canonical URL
Author: soumik

Modification Description::
Adds canonical URLs to index, viewtopic and viewforum pages as specified by Google (Specify your canonical - Official Google Webmaster Central Blog).

Modification Version:: 0.1.2

Features:
A <link> tag is added to the <head> section of the page.
  • For the index page :

    Code: Select all

    <link rel="canonical" href="https://www.example.com/" />
  • For forum pages :

    Code: Select all

    <link rel="canonical" href="https://www.example.com/viewforum.php?f=X" />
  • For threads :

    Code: Select all

    <link rel="canonical" href="https://www.example.com/viewtopic.php?f=X&t=Y" />
  • For global threads* :

    Code: Select all

    <link rel="canonical" href="https://www.example.com/viewtopic.php?t=Y" />
This may help with SEO and problems relating to potential/existing duplicate indexing of threads and forums.

Compatibility:
  • Works with 3.0.+ Including 3.0.6
  • Prosilver Compatible
  • subSilver2 Compatible
Image
Image

Demo URL: https://animorphsfanforum.com

Modification Download: Latest Version



Note:

Normally, global threads will have canonical URLs like this :

Code: Select all

https://www.example.com/viewtopic.php?t=X
If you want the global threads to have canonical URLs with an "f=Y" query string, you just need to make a little change to the code. After installing the mod, open viewtopic.php.
Find :

Code: Select all

	'U_CANONICAL' 	=> generate_board_url() . "/viewtopic.$phpEx?" . (($topic_data['topic_type'] == POST_GLOBAL) ? '' : "f=$forum_id&") . "t=$topic_id" . (($start) ? "&start=$start" : ''),
In-line Find :

Code: Select all

''
Replace with :

Code: Select all

"f=Y&"
Replacing 'Y' with the forum id of the forum you want your global threads to belong to.
Last edited by soumik on Tue Dec 01, 2009 5:00 pm, edited 12 times in total.
Powered by chocolate
User avatar
olalavui
Registered User
Posts: 104
Joined: Sat Dec 13, 2008 3:02 am
Location: Vietnam
Name: Bui Thanh Tung
Contact:

Re: [ALPHA] Canonical URL

Post by olalavui »

Thank you ;)
masterbas
Registered User
Posts: 51
Joined: Tue Aug 14, 2007 5:19 pm
Location: The Netherlands
Contact:

Re: [ALPHA] Canonical URL

Post by masterbas »

Nice mod! Can't wait until release!
User avatar
imkingdavid
Former Team Member
Posts: 2673
Joined: Sun Jul 26, 2009 7:59 pm
Location: EST
Name: David King

Re: [ALPHA] Canonical URL

Post by imkingdavid »

That's a neat idea. My site has the forum in a sub folder, but uses the same overall header for the website pages in the root folder. How would I add this to my site? (for instance, /index.php is the home page, and then /board/index.php is the forum index page, but both use the overall_header.html file to set up the pages).

Thanks!
-David
Don't forget to smile today. :)
Please do NOT contact for support via PM or email.
User avatar
DoYouSpeakWak
Registered User
Posts: 2311
Joined: Fri Jul 25, 2008 1:32 pm
Location: Island of Wak-Wak
Contact:

Re: [ALPHA] Canonical URL

Post by DoYouSpeakWak »

imkingdavid wrote:That's a neat idea. My site has the forum in a sub folder, but uses the same overall header for the website pages in the root folder. How would I add this to my site? (for instance, /index.php is the home page, and then /board/index.php is the forum index page, but both use the overall_header.html file to set up the pages).

Thanks!
-David
I use the same setup. But with two diffrent overall_headers.html. one for the board, one for the frontpage, dont know if it can solve this, but worth mentioning.
Whatever you share comes back. Support the phpBB Communities
Offering paid services. 15+ years of experience with phpBB3 and server management.
User avatar
soumik
Registered User
Posts: 486
Joined: Tue Nov 06, 2007 7:27 pm
Contact:

Re: [ALPHA] Canonical URL

Post by soumik »

imkingdavid wrote:My site has the forum in a sub folder, but uses the same overall header for the website pages in the root folder. How would I add this to my site? (for instance, /index.php is the home page, and then /board/index.php is the forum index page, but both use the overall_header.html file to set up the pages.
In that case, as DoYouSpeakWak says, you should use a different header template for your home page. Create a file called main_header.html, duplicate the contents of overall_header.html into it, and do the following changes:
Find :

Code: Select all

<!-- IF CANONICAL_URL --><link rel="canonical" href="{CANONICAL_URL}" /><!-- ENDIF -->
Replace with :

Code: Select all

<link rel="canonical" href="/" />
You also need to change the include tag in the template file the generates the home page.
Find :

Code: Select all

<!-- INCLUDE overall_header.html -->
Replace with :

Code: Select all

<!-- INCLUDE main_header.html -->
Powered by chocolate
demon327
Registered User
Posts: 847
Joined: Thu Nov 16, 2006 2:16 pm

Re: [ALPHA] Canonical URL

Post by demon327 »

Nice mod, but there is one little problem, it ads and extra "amp;" like this:

Code: Select all

http://localhost/ashladan2/forum/viewtopic.php?f=116&t=1725
so the url won't work, but its easy to fix;

Open viewtopic.php
find:

Code: Select all

'CANONICAL_URL' => "{$board_url}/viewtopic.$phpEx?" . (($topic_data['topic_type'] == POST_GLOBAL) ? '' : "f=$forum_id&") . "t=$topic_id" . (($start) ? "&start=$start" : ''),
In-line find:

Code: Select all

f=$forum_id&"
In-line remove:

Code: Select all

amp;
now it should work, although i don't know if this is correct. :)
User avatar
soumik
Registered User
Posts: 486
Joined: Tue Nov 06, 2007 7:27 pm
Contact:

Re: [ALPHA] Canonical URL

Post by soumik »

'&' should be converted to '&' when parsed by a browser. I don't think there is any issue regarding this.
Powered by chocolate
demon327
Registered User
Posts: 847
Joined: Thu Nov 16, 2006 2:16 pm

Re: [ALPHA] Canonical URL

Post by demon327 »

soumik wrote:'&' should be converted to '&' when parsed by a browser. I don't think there is any issue regarding this.
it does not convert it, although al of my urls look like that in my source code..but they work... and when i use the original code of youre mod and i go to that url it says "The requested topic does not exist." :(

Update; even on youre own demo board it's not working ;)
Last edited by demon327 on Sun Nov 15, 2009 2:36 pm, edited 1 time in total.
User avatar
imkingdavid
Former Team Member
Posts: 2673
Joined: Sun Jul 26, 2009 7:59 pm
Location: EST
Name: David King

Re: [ALPHA] Canonical URL

Post by imkingdavid »

soumik wrote:
imkingdavid wrote:My site has the forum in a sub folder, but uses the same overall header for the website pages in the root folder. How would I add this to my site? (for instance, /index.php is the home page, and then /board/index.php is the forum index page, but both use the overall_header.html file to set up the pages.
In that case, as DoYouSpeakWak says, you should use a different header template for your home page. Create a file called main_header.html, duplicate the contents of overall_header.html into it, and do the following changes:
Find :

Code: Select all

<!-- IF CANONICAL_URL --><link rel="canonical" href="{CANONICAL_URL}" /><!-- ENDIF -->
Replace with :

Code: Select all

<link rel="canonical" href="/" />
You also need to change the include tag in the template file the generates the home page.
Find :

Code: Select all

<!-- INCLUDE overall_header.html -->
Replace with :

Code: Select all

<!-- INCLUDE main_header.html -->
Thanks for the info, and also thanks to DoYouSpeakWak. I'll give it a shot when I get a chance! :)
Don't forget to smile today. :)
Please do NOT contact for support via PM or email.
User avatar
soumik
Registered User
Posts: 486
Joined: Tue Nov 06, 2007 7:27 pm
Contact:

Re: [ALPHA] Canonical URL

Post by soumik »

New version (v0.0.2) available for download.

Changelog:
Contains a minor improvement to how the board URL is handled.
Powered by chocolate
ameeck
Former Team Member
Posts: 6559
Joined: Mon Mar 21, 2005 6:57 pm

Re: [ALPHA] Canonical URL

Post by ameeck »

Nice MOD, this should actually be included in phpBB by default IMHO :)
User avatar
soumik
Registered User
Posts: 486
Joined: Tue Nov 06, 2007 7:27 pm
Contact:

Re: [ALPHA] Canonical URL

Post by soumik »

Thanks. And yes, canonical URL links should be included in phpBB by default. :)
Powered by chocolate
maxwell2
Registered User
Posts: 150
Joined: Fri Apr 10, 2009 1:43 pm

Re: [ALPHA] Canonical URL

Post by maxwell2 »

This mod works with SEO?
User avatar
soumik
Registered User
Posts: 486
Joined: Tue Nov 06, 2007 7:27 pm
Contact:

Re: [ALPHA] Canonical URL

Post by soumik »

maxwell2 wrote:This mod works with SEO?
You mean with an SEO mod? If that modification rewrites the forum and the thread URL, then this won't work with that.
Powered by chocolate
Locked

Return to “[3.0.x] MODs in Development”