htaccess ルールを nginx ルールに「変換」するにはどうすればいいですか?

htaccess ルールを nginx ルールに「変換」するにはどうすればいいですか?

このルールを nginx ルールに「変換」したいと思います。location ブロックは適切な場所だと思いますが、私の解決策は機能しません。

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]

これを試してみた

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

答え1

nginxrewriteディレクティブは無条件に適用されますが、書き換えルールには多くの条件があります。try_files ディレクティブその代わり:

location = /index.php {
    # PHP options
}

location / {
    try_files /public$uri /public$uri/ /index.php?route=$uri;
}

関連情報