Permalink Issue in Wordpress (migrated from Blogger) in LEMP stack

July 22, 2014 1.3k views

I had once moved my blogger site to wordpress. Till then I had to use the following in .htaccess file.

RedirectMatch 301 ^/([0-9]{4})/([0-9]{2})/([^/]+).html$ http://mywpsite.com/$3

Now, after moving my site to Nginx, I could not find a way to implement the above rule so that my old permalinks are maintained in new environment also.

5 Answers

You can use nginx's rewrite directive to implement that:

rewrite ^/([0-9]{4})/([0-9]{2})/([^/]+).html$ http://mywpsite.com/$3 permanent;

I added the code inside the server block but getting error.

nginx -t

nginx: [emerg] directive "rewrite" is not terminated by ";" in /etc/nginx/sites-enabled/wordpress:67

Although, the semi-colon is placed in the code above.

  • Hmm, can you pastebin the contents of /etc/nginx/sites-enabled/wordpress?

The Nginx rewrite docs state:

Note: for curly braces( { and } ), as they are used both in regexes and for block control, to avoid conflicts, regexes with curly braces are to be enclosed with double quotes (or single quotes).

So try,

rewrite "^/([0-9]{4})/([0-9]{2})/([^/]+).html$" http://mywpsite.com/$3 permanent;
Have another answer? Share your knowledge.