redirect to another domain based on IP address

Reinis Rozitis r at roze.lv
Mon May 6 11:17:48 UTC 2019


> We have a website under heavily development. So we divide the site to 3 branches stage, demo and main. What our developers want from me is : "every request from office ip address to main domain must redirect to stage." 


If there is a single IP you can use the if directive (http://nginx.org/en/docs/http/ngx_http_rewrite_module.html#if ) in case of multiple - map (http://nginx.org/en/docs/http/ngx_http_map_module.html ) or geo will be a better approach.


A generic example with if:

if ($remote_addr = 127.0.0.1) {
        return 301 http://stage.aaa.com$request_uri;
 }


rr



More information about the nginx mailing list