Rewrite with regex
nginx at netdirect.fr
Mon Apr 12 12:21:15 UTC 2021
Le 12/04/2021 à 12:19, Francis Daly a écrit :
> On Mon, Apr 12, 2021 at 12:02:32PM +0200, Artur wrote:
> Hi there,
>> This seems to work :
>> rewrite "^/((?:[a-zA-Z0-9]+(?:[-][a-zA-Z0-9])*)+)$"
>> /index.php?short_name=$1 last;
>> However, I suppose there is no way to check the size of $1 here.
> So far, it looks like you want to allow either:
> * 1 letter-or-number
> * 1 letter-or-number, then 0-to-30 letter-or-number-or-hyphen, then
> 1 letter-or-number
No, + means 1 or more.
> and it's probably simplest to do that as two separate "rewrite" rules.
In fact it works as is. The only problem is that there is no simple way
to check the total string length.
But having several rewrite rules may be also a good idea.
Is it possible to check the size of $uri ?
More information about the nginx