1

I just switched my server over from apache2 to nginx and now I am having some issues with my .htaccess rewrites.

<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
    Options -MultiViews
</IfModule>

RewriteEngine On

# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]

# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

I have gathered that in order to make this work on Nginx, I will need to edit the Nginx server block. Would anyone be able to tell me how? Thank you very much in advance.

1

1 Answer 1

0

You can do something like that using try_files:

location (.*) {
  try_files $uri $uri/ /index.php;
}

else you can use .htaccess to nginx converter http://winginx.com/en/htaccess, but as it is an automated process it will not be optimized:

location / {
rewrite ^/(.*)/$ /$1 redirect;
if (!-e $request_filename){
rewrite ^(.*)$ /index.php break;
}
}
2
  • No no no, do not use an .htaccess to nginx converter. It generates junk, as can be seen here. Commented Dec 6, 2015 at 11:01
  • I added informations about not optimal conversion
    – Froggiz
    Commented Dec 6, 2015 at 11:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .