Answer the question
In order to leave comments, you need to log in
How to do rewrite in Nginx without changing the URL in the address bar?
Good afternoon!
I just can’t solve the following problem:
There is a site with a subdomain, for example onetwo.domain.com It is
necessary to make it so that when you enter the address domain.com/one/two/, the site indicated above opens, but what you entered remains in the address bar .
I don’t know if this is possible, but it would be nice if when you enter onetwo.domain.com, there is a redirect to domain.com/one/two/ without a cyclic redirect.
I wrote this code: rewrite ^/one/two/ http://onetwo.domain.com/ last;
but the address in the line changes, because you need to specify a relative path, but I don’t know how to do this with a subdomain.
Answer the question
In order to leave comments, you need to log in
If all this is on the same machine and these are different systems, then you can change root depending on the host. If this is one system, then it can be changed through a single entry point depending on the request, i.e. offload work to the server side, for example:
server {
server_name domain.ru, sub.domain.ru;
if($host = sub.domain.ru) {
return 301 http://domain.ru$request_uri;
}
location / {
try_files $uri $uri/ /index.php?h=$host&q=$uri&$args;
}
}
proxy_pass and the address will remain unchanged.
That is, do not rewrite to location, but proxy_pass onetwo.domain.com/; get at the address you are looking for what lives where the proxy_pass specified.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question