0

I'm having a little problem with some rewrite rules for a website.

My permalinks are now something like domain.com/ID/permalink-ID.html

The old structure of permalinks was domain.com/permalink-ID.html

That ID is an integer number.

How can i create a rewrite rule for nginx so that

domain.com/permalink-ID.html redirects to domain.com/ID/permalink-ID.html

I can do that manually... but there are about 25k posts like that.

Thank you

Aurelian
  • 1
  • 1

2 Answers2

0

Test this one out:

rewrite ^/?permalink-(\d+).html http://domain.com/$1/permalink-$1.html permanent;
Vasili Syrakis
  • 4,558
  • 3
  • 22
  • 30
0

Because the number and the permalink is dynamic, here the proposed solution

    location ~* ^/(((?!/).)+)-(\d+)\.html$ {
        return 301 $scheme://$host/$3/$1-$3.html;
    }

For redirect, you can use return instead rewrite. For explanation the regex scheme, please refer this site.

masegaloeh
  • 18,236
  • 10
  • 57
  • 106