Rewrite url segments to get parameters nginx -
i'm trying few hours solve problem, shouldn't of headache.
i need correct code nginx server acomplish this.
i have url this: https://www.example.com/share/userid/file/
and want rewrite to: https://www.example.com/share/?id=userid&key=file/
i've tried several solutions here in stackoverflow none of them have worked.
i've tried this:
rewrite ^/share/(.*)/(.*)$ /share/index.php?id=$1&key=$2 ;
that works if place index.php file there, can't cause /share/ permalink, not actual folder (wordpress). if this:
rewrite ^/share/(.*)/(.*)$ /share/?id=$1&key=$2 ;
i 404 nginx error.
it seems ^/share/(.)/(.)$ not triggering rewrite, must wrong although i'm looking @ nginx rewrite docs , looks ok.
any ideas? tried try_files no success.
thank you
update:
ok works
rewrite ^(/share/)([0-9]+)/(.*)/$ https://$server_name/share/?id=$2&key=$3 last;
however reason if doesn't work:
rewrite ^(/share/)([0-9]+)/(.*)/$ /share/?id=$2&key=$3 last;
i had add $server_name make work, 1 can explain me why?
i solved issue myself:
rewrite ^(/share/)([0-9]+)/(.*)/$ https://$server_name/share/?id=$2&key=$3 last;
i used ([0-9]+)
cause first parameter integer
however reason if doesn't work:
rewrite ^(/share/)([0-9]+)/(.*)/$ /share/?id=$2&key=$3 last;
i had add
https://$server_name
regards
Comments
Post a Comment