-1

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.

sagar more
  • 91
  • 1
  • 7

1 Answers1

0

What you need is something like below

location ~ ^/[^/]+/abc {
   proxy_pass http://$host/abc;
}
Tarun Lalwani
  • 142,312
  • 9
  • 204
  • 265