rewrite url but show original url + nginx

491 views Asked by At

I am new to nginx. I am trying to redirect to some page ("example.com/randomText/abc") to page ("example.com/abc") with nginx.

location ~ ^/(.*/abc){

#method 1
rewrite (.*) /abc break;

#method 2
#return 301 http://$host/abc;

#method 3
#proxy_pass http://$host/abc/;
#proxy_set_header Host $host;
#proxy_set_header X-Rewrite-URL $request_uri;
}

method 1 and 2 are working but it also change the url to "http://example.com/abc" method 3 return with 502 error.

1

There are 1 answers

0
Tarun Lalwani On

What you need is something like below

location ~ ^/[^/]+/abc {
   proxy_pass http://$host/abc;
}