1

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.

Everyone
  • 21
  • 5
  • 1
    You don't even need a rewrite for that. Just put it in `try_files`. – Michael Hampton Sep 11 '13 at 21:08
  • I was wanting to ask what you have in mind with try_files until I noticed that my question wasn't exactly correct. I'm sorry about that overlook. The problem is that I need to trow out the last part as an 'id' argument and glue remaining arguments to it. I don't think try_files is that powerfull. – Everyone Sep 12 '13 at 19:46
  • is nginx regex like apache's mod_rewrite? `RewriteRule ^.*/(.*)/?\?(.*)$ /index.php?id=$1&$2` ... We need a regex exchange... – Daniel Widrick Sep 12 '13 at 22:28
  • Pretty much yes, except nginx doesn't need a "RewriteCond" and "RewriteRule" is just "rewrite". – Everyone Sep 19 '13 at 10:44

1 Answers1

1

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

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