Welcome! Log In Create A New Profile

Advanced

Create custom variable based on another one

August 04, 2016 08:27AM
Hello there,

I'm trying to set a new variable based on another one.

I've found this response which is kinda close to what i want to do : https://www.ruby-forum.com/topic/6876231#1176774

map $request_uri $last_path {
~/(?<pathname>[^/]+)/?$ $pathname;
}

Except, i want to get the first path level only (and not the file name) !

It seems to work fine even if the syntax seems not really correct, here is what i came up with (and it's working) :

map $request_uri $last_path {
~/(?P<pathname>[^\/]+)/?$ $pathname;
}

But, as soon as i try to make changes in order to get the first path, my $last_path value is empty...
I guess i didn't succed in making all the changes required for it to work...

Here is some of my attemps (please don't laugh), not working :
~/^\/(?P<pathname>[^\/]+)/? $pathname;
~/^\/(?P<pathname>)[^\/]+/? $pathname;
~/^[\/+](?P<pathname>[^\/]+)/? $pathname;
~/^[\/+](?P<pathname>)[^\/]+/? $pathname;


To be clear on what i expect :
/a for /a/b/c.png
/a for /a/c.png
/ for /c.php

Thanks in advance !
Subject Author Posted

Create custom variable based on another one

pixeye August 04, 2016 08:27AM

Re: Create custom variable based on another one

Edho Arief August 04, 2016 09:00AM

Re: Create custom variable based on another one

pixeye August 04, 2016 09:38AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 237
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready