0

I have these htaccess rules:

<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]

and I used an online converter and this is what it gave me, however, it doesn't work, so I'm not really sure what's wrong with it.

location / {
rewrite ^/(.*)/$ /$1 redirect;
if (!-e $request_filename){
rewrite ^(.*)$ /index.php break;
}
}

thanks in advance

Sherif
  • 33
  • 2

1 Answers1

2

In nginx you don't use rewrite for front controllers, instead use try_files. Your configuration should look something like this:

server {
    ...
    try_files $uri $uri/ /index.php;

    location ~ (.+)/$ {
        return 301 $scheme://$host$1;
    }
}
Michael Hampton
  • 237,123
  • 42
  • 477
  • 940
Tero Kilkanen
  • 34,499
  • 3
  • 38
  • 58