Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

afoysal's avatar

Remove index.php from URL

I am using Laravel 5.5.12 in Linux Mint.I am using LAMP stack. I would like to remove index.php from URL. My mod_rewrite apache module enabled.

My .htaccess file located in public folder and it contains following code.

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

    Options +FollowSymLinks

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]

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

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>

I renamed the server.php in the Laravel root folder to index.php and copy the .htaccess file from /public directory to Laravel root folder. But it is not working.

I placed below code in .htaccess file

<IfModule mod_rewrite.c>

  # Turn Off mod_dir Redirect For Existing Directories
  DirectorySlash Off
  
  # Rewrite For Public Folder
  RewriteEngine on
  RewriteRule ^(.*)$ public/$1 [L]

</IfModule>

But this not working.

Could anyone help me in this regard ?

0 likes
5 replies
Cronix's avatar

Are you sure your APP_URL doesn't have index.php in it? Does your app still work if you manually type a url without index.php in it?

1 like
afoysal's avatar

Thanks @Cronix for your reply. No, my App is not working if I manually type a URL without index.php in it. But the App is working fine if I use php artisan serve. Here is my APP_URL

enter image description here

jlrdw's avatar

I renamed the server.php in the Laravel root folder to index.php and copy the .htaccess file from /public directory to Laravel root folder. But it is not working.

Don't do that.

Rather even in development set up laravel correctly following this guide, It works 100 %:

http://novate.co.uk/deploy-laravel-5-on-shared-hosting-from-heart-internet/

  • If you have a problem
  • There is only one rule to follow
  • Follow the guide

I used it for local dev and a hosting server for laravel 5.5.

Please or to participate in this conversation.