miniBB ® 

miniBB

®
Support Forums
  
 | Start | Register | Search | Statistics | File Bank | Manual |
How To miniBB Support Forums / How To /  
 

How to add user selected Canonical info to header?

 
Author Steve Shaw
Partaker
#1 | Posted: 5 Jun 2024 11:44 
Hi Paul,

How can I add a Canonical link to the header page for all the forum pages?

<link href="https://lightillusion.com/forum/????" rel=canonical>

Steve

Author Paul
Lead Developer 
#2 | Posted: 5 Jun 2024 12:35 
I suppose, just edit /templates/main_header.html and paste it there?

Or is it sort of dynamic link which should differ for each page?

Author Steve Shaw
Partaker
#3 | Posted: 5 Jun 2024 21:45 
Yeah — it has to be unique for each page.
So for threads, based on the unique link to each page thread, etc.

It's becoming very important for SEO stuff...

Steve

Author Paul
Lead Developer 
#4 | Posted: 6 Jun 2024 19:42 
I've checked what it's about, and regarding It's becoming very important for SEO stuff — yes, but only if you use the same content on different domains or websites. Then adding a canonical tag on all pages that link back to the definitive page makes sense.

I suppose, it's not your case? Or at least, if you have miniBB-based forum, it's already a definitive source and I doubt it's worth to duplicate a dynamic forum of a certain subject on multiple domains or websites on your own. It could be worth critically though in a case someone steals your forum contents on-the-go.

For the dumb search engines, some other tricks are available already.

First of all, in miniBB there's a built-in ROBOTS tag implementation, which tells a search engine what pages to index (all threads and forum sections) and what to skip (search/registration forms, profiles, topic listings etc.). That way duplicating these pages elsewhere makes no sense, because they are not supposed to be indexed.

Second, on a topic page, the definitive URL is checked each time when you visit it, and if it's not equal to the URL you've typed, you will be redirected to the proper definitive URL. This works for mod_rewrite module updates, .php query strings and so on. You just have no chance to visit an indefitinive URL for such important content as topic/threads.

Third, for miniBB-based forum, you have one and only definitive URL initially, which is set up in $main_url of setup_options.php. And if for example when you have all these URLs available:

* https://www.example.com/forum/
* https://www.example.com/forum
* https://example.com/forum/
* https://example.com/forum


— it is not up putting the Canonical tag at all. You have to set up proper redirections in .htaccess for example (having an Apache web-server), and redirect to the definitive URL from www to non-www version, or otherwise, from non-www to www. Also cover the ending backslash, redirecting from non-backslash version to backslash version — all this should be set up on the physical server or script handling and not with the Canonical meta-tag.

There's one small issue which couldn't be easily tracked on the server level, which is when you have both URLs available like this:

* https://www.example.com/forums/index.php
and
* https://www.example.com/forums/

— i.e. the forums could be opened both via index.php and without it. Then putting the code below in setup_options.php — above the very ending ?> tag — could help to solve this:

/* Handling index.php properly for definite URLs ending with a backslash */
$requrl=strtolower($_SERVER['REQUEST_URI']);
if(isset($_SERVER['SERVER_PROTOCOL']) and ($_SERVER['SERVER_PROTOCOL']=='HTTP/1.0' or $_SERVER['SERVER_PROTOCOL']=='HTTP/1.1') ) $proto=$_SERVER['SERVER_PROTOCOL']; else $proto='HTTP/1.1';
if(!isset($rheader)) $rheader='Location:';
if(substr_count($requrl, 'index.php')>0 and sizeof($_GET)==0 and sizeof($_POST)==0){
header($proto.' 301 Moved Permanently');
header($rheader.$main_url.'/');
exit;
}
Note: this is only for the case when your definite forum URL ends with a slash and it shouldn't be opened via index.php.

The Canonical meta tags implementation was actually in my ToDo list for the next miniBB releases, but I may think to implement them straight in the next miniBB update which is planned this summer.

It's not easy on the add-on level and also it should be optional, because as I know, many miniBB-based forum admins do not have Apache and run the forum without Keyword-rich URLs module, and there could be other circtumstances which do not require definite URLs at all, so — this is custom for each domain.

But like I mentioned all above, for a unique forum you probably have, the Canonical meta tag doesn't make sense if you handle all definite URLs with redirections, like described.

Author Steve Shaw
Partaker
#5 | Posted: 12 Jun 2024 18:12 
The issue is actually www vs. non-www urls.
Without a canonical defined both are seen as duplicates.

Steve

Author Paul
Lead Developer 
#6 | Posted: 13 Jun 2024 19:41 
Steve Shaw:
The issue is actually www vs. non-www urls.
Without a canonical defined both are seen as duplicates.
It could not be solved just with HTML tag, because HTML tags are always a recommendation for the search engine, and not something definitely strict. Actually we don't even know how the crawler works, so these are just expectations.

You should avoid www vs. non-www issue, providing the proper redirections on the server level — in .htaccess as for example if you have Apache (I hope you do). I've mentioned that above.

Author tom322
Active Member
#7 | Posted: 21 Aug 2024 21:26 
Google is a mess and has been for years now. They clearly state that when you have a 301 redirection you don't have to have a canonical to the permanently-redirected location and it is obvious and logical. They will get it right at some point, I'd hope.

Author Paul
Lead Developer 
#8 | Posted: 22 Aug 2024 18:37 
tom322:
when you have a 301 redirection you don't have to have a canonical to the permanently-redirected location
It's not just obvious, but in some cases it's even impossible to provide canonical URL in the page source. Let's say you have renamed some topic and you have keywords-rich URLs, that means, URL to the topic will differ from a previous one, having another keywords in it. And let's say this topic's URL is mentioned on external pages, so when someone clicks on frpm there, the forum script will do 301 redirection to the proper actual URL.

Where the canonical tag should be present in this case? Nowhere. Everything happens server-side and a regular user won't even notice there was a redirection to a different URL. But the topic itself could have just a fresh canonical tag, it won't be even accessible under an old URL.

How To miniBB Support Forums / How To /
 How to add user selected Canonical info to header?
 Share Topic's Link

Your Reply Click this icon to move up to the quoted message


  ?
Post as a Guest, leaving the Password field blank. You could also enter a Guest name, if it's not taken by a member yet. Sign-in and post at once, or just sign-in, bypassing the message's text.


Before posting, make sure your message is compliant with forum rules; otherwise it could be locked or removed with no explanation.

 

 
miniBB Support Forums Powered by Forum Software miniBB ® Home  Features  Requirements  Demo  Download  Showcase  Gallery of Arts
Compiler  Premium Extensions  Premium Support  License  Contact Us
Get the Captcha add-on: protect your miniBB-forums from the automated spam and flood.


  ⇑