Skip to main content

NGINX Redirect .html to just slugs

I like Nikola’s pretty URLs feature and have been using it at the personal site.

And after a year of prettiness there and .html here, I decided to switch this site to use it too.
All my urls look nice now :)
Which also means all the old links are now broken.
And so, the last bit of work was to redirect all the links in the wild and on the blog to the new addresses

A quick web search led me to this stackoverflow answer.

#at the top of location /
if ($request_uri ~ ^/(.*)\.html$) {  return 302 /$1;  }

#within \.php$
if ($request_uri ~ ^/([^?]*)\.php($|\?)) {  return 302 /$1?$args;  }

All I needed was the top bit and all was well, with my world :)

Update: Gave up on the redirect idea, beacause it was breaking pagination on the blog. Well, I tried :)