2

Let's say that i have thousand of old links that i want to redirect, all old links are like mydomain.com/1234-article-slug-name and the new links are like mydomain.com/article-slug-name.

I want to configure my nginx to remove article id from url and redirect to the new url.

I found my solution with apache, but can't figure it out how to achieve it on nginx.

Apache solution:

RewriteCond %{REQUEST_URI} [0-9]+- RewriteRule ^(.*)/[0-9]+-(.*)$ $1/$2 [R=301,L]

2
  • 2
    Please try below nginx configuration location / { if ($request_uri ~ "[0-9]+-"){ rewrite ^/(.*)/[0-9]+-(.*)$ /$1/$2 redirect; } } Sep 4, 2018 at 8:55
  • @sanjayparmar it worked, make an answer so i can set it as correct :) Thanks a lot
    – JoseSilva
    Sep 4, 2018 at 9:02

1 Answer 1

2

Please try below nginx configuration

location / {
  if ($request_uri ~ "[0-9]+-"){
    rewrite ^/(.*)/[0-9]+-(.*)$ /$1/$2 redirect;
  }
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .