1

How to convert .htaccess configuration to nginx?

My .htacess:

Options -MultiViews
RewriteEngine On
RewriteBase /mvc/public
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]

I tried this:

nginx configuration

location /mvc/public/ {
if (!-e $request_filename){
rewrite ^/mvc/public/(.+)$ /mvc/public/index.php?url=$1 [QSA,L];
}
}

But this did not work! Could someone help me?

Charles Dahab
  • 93
  • 2
  • 12

1 Answers1

2

The [QSA,L] is not nginx syntax - see this document for details.

location /mvc/public/ {
    if (!-e $request_filename) {
        rewrite ^/mvc/public/(.+)$ /mvc/public/index.php?url=$1 last;
    }
}

Similar behaviour can be accomplished with try_files rather than the if:

location /mvc/public/ {
    try_files $uri $uri/ @rewrite;
}
location @rewrite {
    rewrite ^/mvc/public/(.+)$ /mvc/public/index.php?url=$1 last;
}

See this document for details.

Richard Smith
  • 45,711
  • 6
  • 82
  • 81