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; } 
1
  • Expand on "doesn't work". What happens? What doesn't happen? What do the logs say? Commented Jan 12, 2020 at 19:50

1 Answer 1

4

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; } 
1
  • Thanks for your really very quick response. This works perfect :) try_files /public$uri /index.php?route=$uri; Commented Jan 12, 2020 at 14:06

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.