Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question
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... –  lVlint67 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 Answer 1

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

 
discard

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.