[TikiWiki-commits] [Git][tikiwiki/tiki][29.x] [BP][FIX][UX] SEO: Use absolute URLs for canonical and alternate hreflang links in wiki pages

"Olivier Kango \(@olivierkango\) via TikiWiki-cvs" <[email protected]>
Newsgroups gmane.comp.cms.tiki.cvs
Message-ID <68df2caa71eea_2b595f24232ec@gitlab-sidekiq-low-urgency-cpu-bound-v2-78f6c68b9-p724q.mail>

Olivier Kango pushed to branch 29.x at Tiki Wiki CMS Groupware / Tiki


Commits:
120c3791 by Olivier Kango at 2025-10-03T04:47:04+03:00
[BP][FIX][UX] SEO: Use absolute URLs for canonical and alternate hreflang links in wiki pages
---
* [FIX][UX] SEO: Use absolute URLs for canonical and alternate hreflang links in wiki pages
---
* [FIX] - Expected 1 space after NOT operator error

* [FIX] Use absolute URLs for hreflang links and avoid duplicate canonicals

* [FIX][SEO] Use absolute URLs for canonical and hreflang links in wiki pages

See merge request tikiwiki/tiki!8443

(cherry picked from commit e3b5a9ab069ae6e4838cf2025c473f7a8ac17633)

See merge request tikiwiki/tiki!8707

- - - - -


1 changed file:

- lib/wiki/renderlib.php


Changes:

=====================================
lib/wiki/renderlib.php
=====================================
@@ -217,16 +217,28 @@ class WikiRenderer
             $links = [];
 
             $wikilib = TikiLib::lib('wiki');
+            global $base_url;
+            $base = rtrim((string) $base_url, '/');
+
             $selfHref = $wikilib->sefurl($this->page);
+            if (! preg_match('~^https?://~i', $selfHref)) {
+                $selfHref = $base . '/' . ltrim($selfHref, '/');
+            }
 
-            $links[] = '<link rel="alternate" href="' . $selfHref . '" hreflang="' . $this->info['lang'] . '">';
+            $links[] = '<link rel="alternate" hreflang="' . htmlspecialchars(strtolower($this->info['lang']), ENT_QUOTES, 'UTF-8') . '" href="' . htmlspecialchars($selfHref, ENT_QUOTES, 'UTF-8') . '">';
 
             foreach ($this->trads as $trad) {
                 if ($trad['lang'] != $this->info['lang']) {
-                    $links[] = '<link rel="alternate" href="tiki-index.php?page=' . $trad['objName'] . '" hreflang="' . $trad['lang'] . '">';
+                    $tradHref = $wikilib->sefurl($trad['objName']);
+                    if (! preg_match('~^https?://~i', $tradHref)) {
+                        $tradHref = $base . '/' . ltrim($tradHref, '/');
+                    }
+                    $links[] = '<link rel="alternate" hreflang="' . htmlspecialchars(strtolower($trad['lang']), ENT_QUOTES, 'UTF-8') . '" href="' . htmlspecialchars($tradHref, ENT_QUOTES, 'UTF-8') . '">';
                 }
             }
-            $headerlib->add_rawhtml(implode("\n", $links) . "\n");
+            if (! empty($links)) {
+                $headerlib->add_rawhtml(implode("\n", $links) . "\n");
+            }
         }
 
         if ($prefs['feature_machine_translation'] == 'y' && $prefs['lang_machine_translate_wiki'] == 'y' && ! empty($this->info['lang'])) {



View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/120c3791aeb5e0b1903832d3de848313ea875b62

-- 
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/120c3791aeb5e0b1903832d3de848313ea875b62
You're receiving this email because of your account on gitlab.com.

_______________________________________________
TikiWiki-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tikiwiki-cvs
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.