2

I would like to "convert" this rules into an nginx rule. I think the location block is the right place, but my solutions doesn't work.

Options -Indexes
RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}/public%{REQUEST_URI} -f
RewriteRule ^(.*)$ public/$1 [QSA,END]
RewriteCond %{REQUEST_FILENAME} !index\.php
RewriteRule ^(.+)$ index.php?route=$1 [QSA,L]

I tried this

location / {
  rewrite ^(.*)$ /public/$1;
  rewrite ^(.+)$ /index.php?route=$1 break;
}
sareew
  • 23
  • 2

1 Answers1

3

The nginx rewrite directive is applied unconditionally, whereas you have many conditions in your rewrite rules. Use the try_files directive instead:

location = /index.php {
    # PHP options
}

location / {
    try_files /public$uri /public$uri/ /index.php?route=$uri;
}
Piotr P. Karwasz
  • 5,748
  • 2
  • 11
  • 21
  • Thanks for your really very quick response. This works perfect :) `try_files /public$uri /index.php?route=$uri;` – sareew Jan 12 '20 at 14:06