John Siu Blog

Tech - Business Tool, Personal Toys

Nginx Redirect For WordPress Permalink

☰ Table of Content

Seems URL rewrite/redirect is a never ending story.


When I switched my blogging platform from Ghost to Hugo, I also switched the web serving component.

I used my own h2ghost with Ghost as both were nodejs applications.

However Hugo produce static pages and I decided to look into other http server options.

I was debating between Monkey Server and Nginx. And finally pick Nginx as it is more actively developed.


Log was set to minimum when I was using h2ghost. But once I switched to Nginx, Logwatch start showing the 404 listing. To my surprise, other than all the random attacks, there are a few old WordPress permalink popping up.

/index.php/2012/12/06/tiny-vps-postfix/: 1 Time(s)
/index.php/category/phone/: 1 Time(s)
/index.php/sample-post/: 1 Time(s)
/index.php/tiny-vps-postfix/: 1 Time(s)


To save those requests, I need to implement redirect/rewrite again, just like old times. Luckily the regex from my old Lighttpd still works.

# /index.php/YYYY/MM/DD/<article> to /blog/<article>
location ~ "^/index.php/\d{4}/\d{2}/\d{2}/(.*)$" { return 301$1; }
# /index.php/<article> to /blog/<article>
location ~ "^/index.php/(.*)$" { return 301$1; }

Now /index.php/tiny-vps-postfix/ works again!!

John Siu

Update: 2020-09-01
comments powered by Disqus