Home > Software engineering >  Problem to redirect url through NGINX when filtering some part
Problem to redirect url through NGINX when filtering some part

Time:11-10

I've been trying to redirect a URL to another domain/URL via NGINX, where it should take the value of a Query String and add only its value to the end of the destination URL, instead of the entire Query String(key:value )

The objective is that when accessing the page: https://site.sandbox.com.br/cadastro/?i=5556

Get directed to the page: https://admin.dev.com.br/create/5556

Removing the question mark, i= and leaving just the numbers only.

The closest I could get was using a regex to match the Location and using the $args variable to append the Query String to the end of the new URL:

    location ~ ^/cadastro/?(.*) {
        return 301 https://admin.dev.com.br/create/$args;
    }

However, using this way the address of the new URL keeps the key:value, it can only remove the question mark: https://admin.dev.com.br/create/i=5556

I tried several ways, using rewrite and return, with different combinations, without success. In most cases there is no match and nothing happens. Here is the page containing the attempts: https://pastecode.io/s/fafc5wj4

How can I make this modification in args, so that it only brings the value of the Query String?

CodePudding user response:

I had the same problem some time ago.. following

CodePudding user response:

I'm currently having this problem, I've tried some alternative ways to fix it, but to no avail. I'm waiting for someone who can help solve the problem mentioned above.

  • Related