Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
132 views
in Technique[技术] by (71.8m points)

How to edit url without updating in browser - nginx config

I want the Request URL to be converted from http://host.com/newname/abc?def= to http://newname/abc?def= here is the config file

server {
    listen 80;
    server_name
        host.com

location / {

    rewrite ^(.+)/$ $1 permanent;
    rewrite ^(.+)/index.html$ $1 permanent;
    rewrite ^(.+).html$ $1 permanent;

      try_files /$host/public/$uri @webserver;
      }
   }

Adding above line worked form me

location / {
            rewrite ^ $scheme://$request_uri? permanent; 
    }

But it replaces the url in user browser which i donn't want to happen. Any way to achieve it

question from:https://stackoverflow.com/questions/65949557/how-to-edit-url-without-updating-in-browser-nginx-config

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can try this:

location /newname{
  proxy_pass http://example.com/newname/abc?def=;
}

or

location /newname{
  proxy_pass http://newname/abc?def=;
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...