Ask For Nginx Rewrite URL Condition

Please help me with url rewriting on nginx.
I have a wordpress site with some example of urls structure like this:

http://example.com/1/hello-world/
http://example.com/9999/this-is-page-title-/

Then I decided to change permalink structure from /%post_id%/%postname%/ to /%postname%.html.

So at this point, url permalink structure of my wordpress is:

http://example.com/this-is-title-page.html

Currently I’ve made a nginx rewrite rules:

rewrite ^/[0-9]+/(.*) http://example.com/$1 permanent;

This url rewrite only works if user entered url by adding .html manually to end of the url.

But what I want is nginx automatically redirecting if user entered or clicking url:

http://example.com/9999/this-is-title-page/ **OR** 
http://example.com/this-is-title-page/ **OR** 
http://example.com/this-is-title-page 

Redirect to

http://example.com/this-is-title-page.html 

Can someone help me with nginx rewriting rules like that?


Source: wordpress

Leave a Reply