Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

With an URI like


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


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

share|improve this question
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

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

rewrite /?([A-Za-z0-9_-]+)/?$ /index.php?id=$1&$2 last;
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.