Nginx + regex, remove all parts of URI except the last one

nginxregexremoverewriteuri

With an URI like

/a-part/some-part/another-part/last-part/?some_param=some_value

how do I go about removing everything up to the last part with params and ultimately rewrite it to look like

/index.php?id=last-part&some_param=some_value

?. I tried all kinds of magic but the closest I got was removing everything up to question mark.

Best Answer

Finally got it. This is what seems to be working:

rewrite /?([A-Za-z0-9_-]+)/?$ /index.php?id=$1&$2 last;
Related Topic