Quantcast
Channel: Nginx Forum - How to...
Viewing all articles
Browse latest Browse all 4759

Nginx location group capture + rewrite?

$
0
0
I'm trying to do a group capture in a Nginx location block and it's not working for me.

Is what I am trying to do even possible?

location ~* /(?<cat>cars|trucks|bikes|motorcycle|quads) {
rewrite ^/$cat/([0-9]+)(.*)$ /page.php?id=$1 last;
}

The error message I am receiving is :

"^/$cat/([0-9]+)(.*)$" does not match "/cars/120/new-car-rentals/"

I have a lot more categories than what I am posting, and trying to prevent writing a rewrite 5x for each specific category name.

This is where I got the syntax from : http://nginx.org/en/docs/http/server_names.html#regex_names

Any help would be appreciated.

Viewing all articles
Browse latest Browse all 4759

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>