mirror of
https://github.com/peter-tanner/peter-tanner.github.io.git
synced 2024-11-30 12:00:18 +08:00
New posts: _posts/2024-06-29-Adding-the-canonical-tag-to-Gitea-to-prevent-duplicate-spam.md
This commit is contained in:
parent
7ad622db70
commit
538d3f4088
|
@ -0,0 +1,24 @@
|
|||
---
|
||||
title: Adding the canonical tag to Gitea to prevent duplicate spam
|
||||
author: peter
|
||||
date: 2024-06-29 02:55:28 +0800
|
||||
categories: [SelfHosting] # Blogging | Electronics | Programming | Mechanical
|
||||
tags: [tip] # systems | embedded | rf | microwave | electronics | solidworks | automation
|
||||
# image: assets/img/2024-06-29-Adding-the-canonical/preview.png
|
||||
---
|
||||
|
||||
Gitea doesn't include the canonical tag in their pages, leading to a lot of duplicate pages being indexed by Google. Each page being indexed has a different sorting option, or other superflous parameter.
|
||||
|
||||
![Search console page getting spammed with duplicate urls](/assets/img/2024-06-29-Adding-the-canonical/search%20console.png)
|
||||
|
||||
To fix this,
|
||||
|
||||
1. Create a `custom/templates/base/` directory under your Gitea installation. In my case it is in `/var/lib/gitea/custom/templates/base/`.
|
||||
2. CD to the base directory and run `wget https://raw.githubusercontent.com/go-gitea/gitea/main/templates/base/head.tmpl`. Make sure your Gitea is updated to the latest version, or choose the right version instead of the `main` branch.
|
||||
3. Modify `head.tmpl`: Add this line somewhere in the `<head>` section:
|
||||
|
||||
```html
|
||||
<link rel="canonical" href="{{AppUrl}}{{if $.Link}}{{slice $.Link 1}}{{end}}" />
|
||||
```
|
||||
|
||||
4. Restart the gitea service
|
BIN
assets/img/2024-06-29-Adding-the-canonical/search console.png
Normal file
BIN
assets/img/2024-06-29-Adding-the-canonical/search console.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 41 KiB |
Loading…
Reference in New Issue
Block a user