I am trying to rewrite a semi static URL path to a dynamic path without much luck. In full transparency, I am pretty new to NGINX and regex, so please bare with me.
I am redirecting from this path: /locations/schedule-tour/locationnumber (this is a real number and dynamic based on the location you are viewing) and I want it to redirect to a path like this: /locations/state/city/address--locationnumber. I can get the location number and #scheduletour to come to the new URL, but I can't figure out how to get the state/city/address portion of the URL to come across. Even looking at rewriting the path name in the server block has stumped me because I don't know how to pull in that state/city/address portion.
You can see what I've tried below. But even if I can change the path name instead of doing a rewrite, then how do I capture the state/territory abbreviation, city name and address dynamically in nginx? Simple redirects have been relatively easy for me, but this one is kicking my butt. Any help is greatly appreciated!
I have tried this:
rewrite (?i)^/locations/schedule-tour/(\d+)$ /locations/$2--$1%23scheduletour permanent;
rewrite (?i)^/locations/schedule-tour/(\d+)$ /locations/(.*)--$1%23scheduletour permanent;
The second attempt worked the best, but obviously is showing (.*) in the URL instead of the state/city/address/ that I actually need.