Quantcast
Channel: Nginx Forum
Viewing all articles
Browse latest Browse all 53287

How to write URI and make browser show original URL instead of rewritten URL?

$
0
0
Hi,

I use nginx with tomcat. In nginx config, there are server 'www.360zhenbao.com' and '*.360zhenbao.com'. In rewrite rule, the 'abc.360zhenbao.com' is rewritten to 'www.360zhenbao.com/show/abc', and 'abc.360zhenbao.com/modify/xxx' is rewritten to 'www.360zhenbao.com/modify/abc/xxx'.

When input 'abc.360zhenbao.com' in browser, the browser turn to show the rewritten URL, i.e. 'www.360zhenbao.com/show/abc' and display the web page content correctly.

How to configure nginx so that the browser shows original URL, i.e. 'abc.360zhenbao.com' instead of the rewritten URL?

=========
upstream localhost{
server 127.0.0.1:8080 weight=1;
#ip_hash;
}

server {
listen 80;
server_name www.360zhenbao.com;
server_name_in_redirect off;

#charset koi8-r;

#access_log logs/host.access.log main;

if ( $host ~* (\b(?!www\b)\w+)\.\w+\.\w+ ) {
set $subdomain /show/$1;
}

location / {
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://localhost;
}

server {
listen 80;
server_name *.360zhenbao.com;
server_name_in_redirect off;

#charset koi8-r;

#access_log logs/host.access.log main;

if ( $host ~* (\b(?!www\b)[-\w]+)\.\w+\.\w+ ) {
set $subdomain $1;
}

location = / {
rewrite ^ /show/$subdomain break;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://localhost;
}

location / {
rewrite ^/(\w+)/(.*)$ /$1/$subdomain/$2 break;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://localhost;
}

Thanks

Viewing all articles
Browse latest Browse all 53287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>