When I was hosting this blog in my own VPS, I followed the URL pattern of "/blog/yyyy/mm/blog-post", which worked quite well for my setup. But I decided to switch to a simpler URL pattern when I moved my blog to Firebase hosting.
I did not want the date part in the URL. Specifically, I wanted to host my blog pages under a simple URL of "/blog/blog-post/".
It turns out that setting up this redirect is quite simple in Firebase. All I needed was to define the redirect rule in the firebase.json
file and I am all set.
Firebase hosting redirect rule to remove date from blog post URL
{
"hosting": {
... other configuration,
"redirects": [
{
"regex": "/blog/\\d{4}/\\d{2}/(?P<post>.+)/",
"destination": "/blog/:post",
"type": 301
}
]
}
}
And that'd be it. This saved me from lots of 404s that I was seeing in my blog lately.