Welcome! Log In Create A New Profile

Advanced

Rewrite with regex

Artur
April 12, 2021 05:32AM
Hello !

I have the following setup :

location / {
 try_files $uri $uri/ @shortnames;
}
location @shortnames {
 rewrite "^/([a-zA-Z0-9]{1,32})$" /index.php?short_name=$1 last;
 return 404;
}

I filter the 'shortnames' URI to have a format similar to /dfg6df4g64
with minimum and maximum size, only digits and letters allowed. Working
well.

I want to add hyphen in the 'shortnames' so /ad5-ff56 or
/5f9-dfdf4-55f-ddfg are allowed ( but not /-ff4fg or /dgfgdf- ).
The regex that matches these conditions is something like (without the
size match) : ^/([a-zA-Z0-9]+([-][a-zA-Z0-9])*)$
However there is no match and rewrite fails.

My current setup is a Debain 10 server with nginx-full (14.2.2) installed.

Any idea on how I can solve this problem, please ?

--

Best regards,
Artur

_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

Rewrite with regex

Artur April 12, 2021 05:32AM

Re: Rewrite with regex

Artur April 12, 2021 06:04AM

Re: Rewrite with regex

Francis Daly April 12, 2021 06:20AM

Re: Rewrite with regex

Artur April 12, 2021 08:22AM

Re: Rewrite with regex

Francis Daly April 12, 2021 08:48AM

Re: Rewrite with regex

Artur April 12, 2021 09:02AM

Re: Rewrite with regex

Francis Daly April 12, 2021 05:14PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 87
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready