Nginx redirect preserving source hostname

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Nginx redirect preserving source hostname

Игнатенко Максим

I have an NGINX as reverse proxy with PHP-fpm. Nginx is set up for serving www.somehost.com. I added another host www.anotherhost.com. Now I need to setup redirect in this way: If user type www.anotherhost.com then it redirects to www.somehost.com/someurl, but url in browser bar shouldn't change. If I set up rewrite it works, but it rewrites url in browser too.

if ($host = "www.anotherhost.com") {
   rewrite ^ http://www.somehost.com/someurl;
}

Is it possible to redirect preserving url ?


_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Nginx redirect preserving source hostname

Francis Daly
On Mon, Apr 03, 2017 at 02:17:19PM +0600, Игнатенко Максим wrote:

Hi there,

> I have an NGINX as reverse proxy with PHP-fpm. Nginx is set up for
> serving www.somehost.com. I added another host www.anotherhost.com.
> Now I need to setup redirect in this way: If user type
> www.anotherhost.com then it redirects to www.somehost.com/someurl,
> but url in browser bar shouldn't change.

> Is it possible to redirect preserving url ?

A "redirect" is an "external rewrite", which asks the browser to make
a new request, and therefore change the url the browser shows.

If you want the browser not to make a new request, you need to handle
the request internally, within nginx, possibly by means of a proxy_pass
(if the desired resource is only available in another server{}).

Good luck with it,

        f
--
Francis Daly        [hidden email]
_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Loading...