Rewriting URL's with httpd.conf
This is just a quick note for myself to remind me the next time I try to setup some sort of URL redirection on my web server.
The majority of the contents on my web site is my blog and Hugo does a pretty good job of organising all of the blog contents so I don't need to think about it.
I also have a few non-blog style pages that I'm hosting and while their locations and URL's make sense to me, they're not always the easist to pass on to someone else, unless you're sending them a URL in an email or chat message. I won't go into full details here for the page I was trying to get sorted, but I've expanded it to include my Now page using the same format and that's the example I'll include below. I can extrapolate for any other pages as needed.
Having a nice and easy to remember (and less memory failure prone) URL for my Now page like martin.hatstand.org.uk/now
and having my web server deal with getting it to the actual page is easier than having folks remember that it martin.hatstand.org.uk/pages/now
.
I know, it's simple enough, but I'm lazy and people forget, so I've been looking at ways to get the web server to just deal with the alternative URL instead and I'm pleased to report that using OpenBSD and the native httpd web server, it's pretty simple as long as you remember you need to specify a destination file name, at least as far as I can make out anyway. Trying to forward the connection to the directory, like the original URL would, doesn't seem to work, at least for me.
No problem, I'll just do it like this. This section needs to live inside the main server
block for your site.
location match "/now" {
request rewrite "/pages/now/index.html"
}
Yep, that seems to work for my Now page as well as the other page I was was working on.