2

Here's my requirement for redirecting in Nginx -

Redirect Example
1. www.example.com/gaming.html -> www.example.com/gaming-zone.html

No Redirect example (when params are present, dont redirect)
2. www.example.com/gaming.html?name=foo -> www.example.com/gaming.html?name=foo 

I have a very simple redirect setup up -

rewrite ^/gaming.html$ /gaming-zone.html redirect;

which satisfies example 1 but redirects example 2 as well. Can someone please share how to fix the rule so that URLs containing params are not redirected?

1 Answer 1

6

It does not seem you tried to at least try to get information....

According to the nginx http core module documentation. You can use either $is_args or $args or $arg_name.

Hence you can simply use the following line:

if($is_args = ""){
    rewrite ^/gaming.html$ /gaming-zone.html redirect;
}

Since you want the second url not to change, there is no need to do anything with that url.

0

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.