How to Configure 301 Trailing Slash Redirect for Github/GitLab Pages?

This may sounds silly but…how to configure the current 302 redirect to 301 (permanent) redirect for tailing slash URL? Example:

https://www.example.com/en ----301----> https://www.example.com/en/

Hosting servers are Github Pages / GitLab Pages.

Thanks in adv.

you are n linux?
try to use VIM with regex replacement

someting like here
substitute - Find and replace using regular expressions - Vi and Vim Stack Exchange

On Windows Notepad++ could do this

Excuse me? I’m not getting you. I’m referring to response code.

OK, in my mind you wanted to change it in markup files …
If not, this is HUGO space, ask in a gihub forum.

After some digging, to configure response code for Hugo’s artifacts, although using
<meta http-equiv="refresh" content="0;url={{ .URL }}"> is the easiest hinting to crawler for 301 redirect. However, this will cause certain web linters to report bad 302 usage.

As for configuring HTTP response code, one needs to configure the proxy server that is serving it.

On GitLab Pages : https://docs.gitlab.com/ee/user/project/pages/redirects.html
On Github Pages : not available.

@jun52, Not sure exactly which part of thing is offending you. FYI, Hugo is highly recommended for building Gtihub and GitLab pages. It is only natural to ask for Hugo in case the team has native supports for certain configurations.

Appreciate if we stop the passive-aggressive assault. TQ. Thanks for your time on the good side. Peace out.

Never mind to be aggresive :wink:

Redirects can be generated by aliases in frontmatter
URL Management | Hugo (gohugo.io)

If you must customize the aliases
URL Management | Hugo (gohugo.io)

sample:

<!DOCTYPE html>
<html {{ with site.Language.Lang }}lang="{{ . }}"{{ end }} >
<head>
	<title>Page Redirection</title>
	<link rel="canonical" href="{{ .Permalink }}"/>
	<meta name="robots" content="noindex">
	<meta http-equiv="refresh" content="0; url={{ .Permalink }}" />
	<script type="text/javascript">window.location.href = "{{ .Permalink }}";</script>
</head>
<body>
The current site is <a href="{{ .Permalink }}">here</a>!
</body>	
</html>

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.