I have problems to convert a htaccess file to nginx. Maybe someone can help me.
I need the following code converted:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
I tried this but this doesnt work at all:
location / {
try_files $uri $uri/ /index.php?$args;
}
2
Answers
I found out that this works:
But is it safe?
(I’m assuming your
.htaccess
file was in the document root.)Your Apache
RewriteRule
directive is passing the URL-path as path-info to theindex.php
script, so your Nginx directive should be something like the following instead:$uri
already contains the slash prefix. Apache also passes the query string through by default, but in Nginx you’ll need to append$is_args$args
. ($is_args
simply contains?
when the$args
(query string) is non-empty.)