0

I've been trying for weeks to convert rewrite rules from a .htaccess to nginx rewrite.

The original file looked like this:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php?/$0 [PT,L] 

Converted

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 /.* /index.php?/$0 last;
}

But when I restart nginx I get:

nginx: [emerg] unknown "0" variable
nginx: configuration file /usr/local/nginx-1.8/conf/nginx.conf test failed

2

Automatic converters such this one can give you a pretty good start...

# nginx configuration
location / {
    if (!-e $request_filename){
         rewrite ^(.*)$ /index.php?/$0 break;
    }
}

Of course if is evil, which is why this manual to converting mod_rewrite directives gives an even better option

location / {
    try_files $uri $uri/ /index.php?$args;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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