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

"luci \(@luciash\) via TikiWiki-cvs" <[email protected]>
Newsgroups gmane.comp.cms.tiki.cvs
Message-ID <68dee8ac2aaad_2c61f2ca410113a@gitlab-sidekiq-low-urgency-cpu-bound-v2-58457f7db6-q9ld4.mail>

luci pushed to branch master at Tiki Wiki CMS Groupware / Tiki


Commits:
e3b5a9ab by Olivier Kango at 2025-10-02T20:55:14+00:00
[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

- - - - -


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/e3b5a9ab069ae6e4838cf2025c473f7a8ac17633

-- 
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/e3b5a9ab069ae6e4838cf2025c473f7a8ac17633
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.