ravindu1024
ravindu1024

Reputation: 1534

How do I redirect certain paths with wildcards with Nginx?

For example I need to redirect urls that match this pattern and keep the rest.

aaa.mydomain.com/path/1/listing

to

bbb.somedomain.com/path/1/listing

The "1" in that path can be any integer and needs to go to the correct redirect. Can this be done with a location block or do i need rewrite?

Upvotes: 1

Views: 2431

Answers (1)

IVO GELOV
IVO GELOV

Reputation: 14259

You can do it like this

server {
  server_name aaa.mydomain.com;
  return 301 //bbb.somedomain.com$request_uri;
}

UPDATE

Well, then use something like this

location ~ /path/[^/]+/listing$ {
  return 301 https://bbb.somedomain.com$request_uri;
}

Upvotes: 1

Related Questions