convert lighttpd to nginx rewrite rules

user3355434 asked:

I’m trying hard to make my code work on nginx. This configuration works with lighttpd but I want migrate it to nginx.

Rewrite rules on lighttd :

url.rewrite-once = (
 "^/(ui)/(.*)$" => "/gi.php/$1/$2",
 "/(.*)\.(.*)" => "$0",
 "/(xhr|js-api)/(.*)" => "$0",
 "^/([^.]+)$" => "/gi.php/$1"

Can anyone help in this conversion? I tried using lot of things, including converting it to apache rewrite rules, but none of them worked.

Nginx rule:

if (!-f $request_filename){
       set $rule_0 1$rule_0;
if (!-d $request_filename){
       set $rule_0 2$rule_0;
if ($rule_0 = "21"){
       rewrite ^/(.*)$ /gi.php/$1 last;

Error : 404

Any suggestions?

My answer:

You don’t generally do rewrites in nginx, the same way you do them in Apache or lighttpd. Most such things should be replaced with try_files instead.

A trivial example:

try_files $uri $uri/ /gi.php

See the nginx documentation for more details.

View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.