remove index.php laravel in linux server code example

Example: remove index.php laravel in linux server

Inside /etc/apache2/apache2.conf Replace

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

and

<Directory /usr/share> AllowOverride None Require all granted
to
<Directory /usr/share> AllowOverride All Require all granted

Run these commands

sudo a2enmod rewrite
sudo service apache2 restart

Inside your .htaccess file

DirectoryIndex index.php

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

    RewriteEngine On

    RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
    RewriteRule ^(.*) - [E=BASE:%1]

    RewriteCond %{ENV:REDIRECT_STATUS} ^$
    RewriteRule ^index\.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L]

    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule .? - [L]

    RewriteRule .? %{ENV:BASE}/index.php [L]

</IfModule>

Tags:

Misc Example