0

I want to rewrite a url containing a specific variable path, for one specific user ip only.

http://domain.com/variable

Should become:

http://domain.com/variable/system

However, if there is another path following the /variable path it should remain unchanged. So the following url should stay the same:

http:/domain.com/variable/something-else

I have tried the following code

 if ($http_x_forwarded_for = xxx.xxx.x.xx) {         
           rewrite ^/(.*)$ http://domain.com/$1/system redirect;
 }

However, when running this code it seems to get an a loop, resulting in

http://domain.com/variable/system/system/system/system ....

I understand what goes wrong, but I do not know how I can easily / correctly fix this. Any help would be greatly appreciated.

2

Your (.*) captures the / character too. You need to exclude it to prevent a loop.

Try:

rewrite ^(/[^/]+)$ $1/system redirect;

See this useful resource on regular expressions.

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.