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


Should become:


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


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.


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


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.