1

I am redirecting the URL from one domain to another using the nginx server block like below:

server {
        server_name subdomain.example.com
        return 301 https://subdomain.example2.com$request_uri;
        }

Now I need to do the same redirection by capturing the URL params as below: https://subdomain.example.com/some-unique-strings/xy000012345 should be permanently redirected to https://subdomain.example2.com/ab/string?stringid=12345 Need to capture the digits after xy0000 dynamically and pass it to new URL as stringid=(captured digits)

0

rewrite and return statements are executed in order. You can place a specific rewrite statement before the general return statement. See this document for details.

For example:

server {
    server_name subdomain.example.com;
    rewrite ^/some-unique-strings/xy0000(.*)$ https://subdomain.example2.com/ab/string?stringid=$1 permanent;
    return 301 https://subdomain.example2.com$request_uri;
}
  • Thanks for the reply, Richard. I have tested this but this still returns the old URL which is request_uri, as it is. This is not rewriting the URL as I want. – user7963704 Sep 18 at 13:36

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.