Search code examples
.htaccessroutessymfony4production-environment

Trying to remove index.php from urls


**I'm working on an apache secured web server hosted on an ubuntu-server.16.04

I'm sending on prod my first project on symfony and I did quite well since now. I'm trying to rewrite url so when I want to go on my project dashboard, the url would be "../dashboard/" instead of (actually like this) "../index.php/dashboard/"

But when I try to go on this url, the server redirect me out of the symfony app and throw me a basic apache 404 error, not a symfony handled error.

I think this can be edited in the .htaccess file but I can't find out how to make him perform all url as symfony routes, that's my question.

Tried multiple code found on google

htaccess

DirectoryIndex index.php
<IfModule mod_negotiation.c>
    Options -MultiViews
</IfModule>

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
    RewriteRule ^(.*) - [E=BASE:%1]
    RewriteCond %{HTTP:Authorization} .
    RewriteRule ^ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
    RewriteCond %{ENV:REDIRECT_STATUS} ^$
    RewriteRule ^index\.php(?:/(.*)|$) %{ENV:BASE}/$1 [R=301,L]
    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule ^ - [L]
    RewriteRule ^ %{ENV:BASE}/index.php [L]
</IfModule>

<IfModule !mod_rewrite.c>
    <IfModule mod_alias.c>
        RedirectMatch 302 ^/$ /index.php/
    </IfModule>
</IfModule>

Solution

  • You need to enable apache rewrite. Please follow these steps : In a terminal use the following commands:

    $sudo a2enmod rewrite
    

    Change AllowOverride in apache conf file:

    $sudo nano /etc/apache2/apache2.conf
    

    Change the AllowOverride from None to All in this block

    <Directory /var/www/>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>
    

    At last, restart apache2

    $sudo service apache2 restart