Search code examples
.htaccesssymfonyhttp-redirectsonata

sonata remove /index.php from urls


I am working on a Symfony 2.8 / Sonata project, and I found that all urls a duplicated, one with "/index.php" and the other witout it. So this url :

http://mydomaine.com/index.php/test/test.html

will be redirected to :

http://mydomaine.com/test/test.html

I tried to use .htaccess to remove it, but it didn't work :

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /index.php?/$1 [L]
    RewriteRule ^(.*)$ app_dev.php [QSA,L]
</IfModule>

Do you have any ideas ? Thanks


Solution

  • Place this rule just below RewriteEngine On to remove index.php from URLs:

    RewriteCond %{THE_REQUEST} /index\.php [NC]
    RewriteRule ^index\.php(/.+)$ $1 [L,R=301,NE]