Answer the question
In order to leave comments, you need to log in
How to redirect to Nginx without changing the url in the browser?
Good afternoon.
There was a need to do the following: there are two sites site.ru, service.ru, both on the same server). you need to make a redirect (without changing the url in the browser) like this:
site.ru/param1/value1/param2/value2... -> service.ru/site?url=param1/value1/param2/value2&site_id=1
On apache this is solved quite simple (.htaccess for site.ru):
RewriteRule ^(.*)$ http://service.ru/site?url=$1&site_id=1 [P]
# И для статики
RewriteRule ^img/(.*\.(eot|font.css|otf|ttc|ttf|woff|js|png|jpg|jpeg|gif))$ http://service.ru/static/1/img/$1 [P]
server {
listen 80;
server_name site.ru www.site.ru;
access_log /var/log/nginx/test1.access.log;
error_log /var/log/nginx/test1.error.log;
location / {
proxy_pass http://site.ru:8080;
}
}
AddDefaultCharset utf-8
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^(.*)$ http://service.ru/site?url=$1&site_id=1 [P]
# И для статики
RewriteRule ^img/(.*\.(eot|font.css|otf|ttc|ttf|woff|js|png|jpg|jpeg|gif))$ http://service.ru/static/1/img/$1 [P]
Answer the question
In order to leave comments, you need to log in
proxy_pass http://service.ru;
proxy_set_header Host service.ru;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question