User Tools

Site Tools


wiki:redirect_another_site_query_parameter_nginx

Redirect to another site from query parameter in nginx

If you have an URL for example:

https://sub.domain.com/some_image?src=https://www.someotherdomain.com/file/thumbnail/blahblah/43433/image.jpg

You can do a redirect to a URL in the src parameter by using below in nginx when visiting above URL.

     location /some_image {
            proxy_pass $arg_src;
            proxy_set_header Host $host;
            resolver 127.0.0.11;
        }

Below could also work (not tested):

location @fetchFromRemote {
        rewrite ^/some_image(.*)$ $arg_src redirect;
    }
 
location ^~ /some_image {
        try_files $arg_src @fetchFromRemote;
    }

Tested on

  • nginx/1.21.4

See also

References

wiki/redirect_another_site_query_parameter_nginx.txt · Last modified: 2022/09/23 13:55 by antisa

Except where otherwise noted, content on this wiki is licensed under the following license: CC0 1.0 Universal
CC0 1.0 Universal Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki