如何將htaccess規則「轉換」為nginx規則?

如何將htaccess規則「轉換」為nginx規則?

我想將此規則「轉換」為 nginx 規則。我認為位置區塊是正確的地方,但我的解決方案不起作用。

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;
}

相關內容