1

When user visits:

/profile.php?mode=viewprofile&u=[NUMBER FROM 1 TO 4000]

I want nginx to return:

/memberlist.php?mode=viewprofile&u=[SAME NUMBER]

How can I do it? Thank you for help.

1 Answer 1

1

The problem is that you need to match /profile.php and mode=viewprofile which is not trivial nginx. There are a number of ways to achieve it.

You could replicate the location ~\.php$ block and add the conditional redirection there:

location = /profile.php {
    if ($arg_mode = viewprofile) {
        return 301 /memberlist.php?$args;
    }
    ... # add location ~\.php$ stuff here
}

Alternatively, check the $request_uri (which contains the original URI including query string), early in the server block:

if ($request_uri ~ "^/profile\.php\?mode=viewprofile&") {
    return 301 /memberlist.php?$args;
}

See this caution on the use of the if statement.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.