I have a couple thousand URL's that look like the following:


This is from my legacy website but our new URL structure looks like the following:


I know how to rewrite single URL's but how would I do a catch all case for all of my id's?


Here's your answer:

location ~ ^/supplier-shop/(?<id>(.*)) {
    rewrite ^ http://$server_name/seller/$id permanent;

Works as well for n level directories as well. Example:

> GET /supplier-shop/asdasd/asdasd HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.47.0
> Accept: */*
< HTTP/1.1 301 Moved Permanently
< Server: nginx/1.10.3 (Ubuntu)
< Date: Thu, 28 Jun 2018 00:10:02 GMT
< Content-Type: text/html
< Content-Length: 194
< Connection: keep-alive
< Location: http://www.example.com/seller/asdasd/asdasd

I guess with a rewrite like the following you may achieve what you are looking for

location ~ ^/supplier-shop/(.+) {
    rewrite ^ http://$server_name/seller/$1 permanent;

Guess the http://$server_name can be omitted, but honestly I don't have an nginx to try what I'm suggesting right now, so better try it and see the results.

Basically the it makes is replacing the "supplier-shop" with the "seller" and taking all that follows and putting into place.

If it's not what you are trying to achieve, let us know

  • All this is doing is stripping everything after /supplier-shop/ and replacing it with seller – NooBskie Jun 22 '18 at 0:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.