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

How can I rewrite following link in nginx?

http://www.example.com/filename/key.value/bar.foo

to

http://www.example.com/filename.php?key=value&bar=foo

Notice .php also, please!

share|improve this question

1 Answer 1

This could be done with the rewrite directive using capture groups, assuming that there are a fixed number of key/value pairs. Dealing with an arbitrary number of key/value pairs would probably require the Lua module.

rewrite ^/([^/]+)/([^/.]+)\.([^/.]+)/([^/.]+)\.([^/.]+)$ /$1.php?$2=$3&$4=$5
share|improve this answer
    
Yes it is going to be an arbitrary number of key/value pairs. How about if you don't have to separate the key.value? You know take that as one variable. I can do the slit in the script. –  RoboTamer Jun 10 '12 at 5:04

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.