Contents

OpenBSD httpd: How to redirect from .html-URLs to non-.html-URLs

Problem

After switching to a new website generator, all pages had moved from .html- to non-.html-URLs.

If Google found my site, the old .html-urls were linked:

./html-url.png
Google linking via non-existing .html-URLs

Clicking a link would refer to 404 - not found.

Solution

To redirect from the non-existing-.html-urls to the new non-.html-urls, I had to add:

1
2
3
4
5
6
7
server "bastianovic.dev" {
  [..]
  location match "/(.*)%.html$" {
    block return 301 "/%1/"
  } 
  [..]
}

to /etc/httpd.conf.

301 tells search engines, that the page has permanently moved, so they will update their search indexes accordingly.

Perform

1
httpd -n && rcctl restart httpd

to check httpd’s configuration and restart httpd.

Caution
This is no solution if you just want to cut off the .html-extension from urls: If your url is /my-page.html, this would redirect to /my-page/ and your website would return 404 - not found. For simple redirecting - when pages doesn’t have moved - you would rather use request rewrite.

References