0

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.

3
  • Welcome to Stack Overflow! Stack Overflow is for programming questions, not questions about using or configuring Unix and its utilities. Unix & Linux or Super User would be better places for questions like this. Commented Apr 16, 2024 at 0:03
  • hey @barmar it is tied specifically to tags available here and there are several other nginx type questions here in Stack Overflow...I'm not sure why this one is different. Commented Apr 16, 2024 at 17:24
  • Many of these tags date to the time before those other sites were spun off. And we don't operate on precedent. Allowing the questions in the past doesn't mean this is the best site for the question now. Commented Apr 16, 2024 at 17:28

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.