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

vikdhr's avatar

remove index.php from laravel5.6

How to remove index.php from http://localhost/lvoffc/index.php/login where "lvoofc" is the name of my project.

http://localhost/lvoffc/index.php/login---> Working http://localhost/lvoffc/login---> Shows "The requested URL /lvoffc/login was not found on this server." http://localhost/lvoffc/index.php/register--> Working http://localhost/lvoffc/register--> Shows "The requested URL /lvoffc/login was not found on this server."

I have tried the options

  1. move the index.php and .htaccess from a public to root directory
  2. rename the server.php to index.php and move the .htaccess file to the root directory. but not getting success to remove index.php from URL
0 likes
30 replies
rin4ik's avatar
rin4ik
Best Answer
Level 50

show your routes please

vikdhr's avatar

@rin4ik Route::get('/', function () { return view('welcome'); });

Auth::routes();

Route::get('/home', 'HomeController@index')->name('home');

This is my web.php file

rin4ik's avatar

@vikdhr

Apache Laravel includes a public/.htaccess file that is used to provide URLs without the index.php front controller in the path. Before serving Laravel with Apache, be sure to enable the mod_rewrite module so the .htaccess file will be honored by the server. If the .htaccess file that ships with Laravel does not work with your Apache >installation, try this alternative:

 Options +FollowSymLinks
 RewriteEngine On
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteRule ^ index.php [L]

EDIT:inside public directory you can find .htaccess file

vikdhr's avatar

@biishmar This is .htaccess

Options -MultiViews -Indexes

RewriteEngine On

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

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

this is index.php that is renamed from server.php to index.php

biishmar's avatar

@vikdhr Your htaccess is fine..

require_once __DIR__.'/public/index.php';

Does your index,php has a last line like this?

vikdhr's avatar

@biishmar This is root index.php

$uri = urldecode( parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH) ); if ($uri !== '/' && file_exists(DIR.'/public'.$uri)) { return false; } require_once DIR.'/public/index.php';

vikdhr's avatar

@biishmar this is index.php of public folder define('LARAVEL_START', microtime(true)); require DIR.'/../vendor/autoload.php'; $app = require_once DIR.'/../bootstrap/app.php'; $kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);

$response = $kernel->handle( $request = Illuminate\Http\Request::capture() ); $response->send(); $kernel->terminate($request, $response);

biishmar's avatar

@vikdhr Public/index.php

<?php

/**
 * Laravel - A PHP Framework For Web Artisans
 *
 * @package  Laravel
 * @author   Taylor Otwell <[email protected]>
 */

/*
|--------------------------------------------------------------------------
| Register The Auto Loader
|--------------------------------------------------------------------------
|
| Composer provides a convenient, automatically generated class loader for
| our application. We just need to utilize it! We'll simply require it
| into the script here so that we don't have to worry about manual
| loading any of our classes later on. It feels great to relax.
|
*/

require __DIR__.'/../bootstrap/autoload.php';

/*
|--------------------------------------------------------------------------
| Turn On The Lights
|--------------------------------------------------------------------------
|
| We need to illuminate PHP development, so let us turn on the lights.
| This bootstraps the framework and gets it ready for use, then it
| will load up this application so that we can run it and send
| the responses back to the browser and delight our users.
|
*/

$app = require_once __DIR__.'/../bootstrap/app.php';

/*
|--------------------------------------------------------------------------
| Run The Application
|--------------------------------------------------------------------------
|
| Once we have the application, we can handle the incoming request
| through the kernel, and send the associated response back to
| the client's browser allowing them to enjoy the creative
| and wonderful application we have prepared for them.
|
*/

$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);

$response = $kernel->handle(
    $request = Illuminate\Http\Request::capture()
);

$response->send();

$kernel->terminate($request, $response);

root/index.php

<?php

/**
 * Laravel - A PHP Framework For Web Artisans
 *
 * @package  Laravel
 * @author   Taylor Otwell <[email protected]>
 */

$uri = urldecode(
    parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)
);

// This file allows us to emulate Apache's "mod_rewrite" functionality from the
// built-in PHP web server. This provides a convenient way to test a Laravel
// application without having installed a "real" web server software here.
if ($uri !== '/' && file_exists(__DIR__.'/public'.$uri)) {
    return false;
}

require_once __DIR__.'/public/index.php';

check those both and tell you have same in ur both index.php

vikdhr's avatar

@biishmar Public/index.php where require DIR.'/../bootstrap/autoload.php'; it is as require DIR.'/../vendor/autoload.php';

If vendor is replaced with bootstrap then it shows blank screen

biishmar's avatar

@vikdhr Yes both r needed, if u find anything different in your index.php change it like this or copy paste this both index.php..

vikdhr's avatar

@biishmar as you say i wrote as

require DIR.'/../vendor/autoload.php'; require DIR.'/../bootstrap/autoload.php';

but not working

vikdhr's avatar

@biishmar i worked on laravel 5.4 version by moving the index.php and .htaccess file from public to root and making changes in index.php that works fine but not in version laravel5.6

biishmar's avatar

@vikdhr What i paste here is exact one

<?php

/**
 * Laravel - A PHP Framework For Web Artisans
 *
 * @package  Laravel
 * @author   Taylor Otwell <[email protected]>
 */

define('LARAVEL_START', microtime(true));

/*
|--------------------------------------------------------------------------
| Register The Auto Loader
|--------------------------------------------------------------------------
|
| Composer provides a convenient, automatically generated class loader for
| our application. We just need to utilize it! We'll simply require it
| into the script here so that we don't have to worry about manual
| loading any of our classes later on. It feels great to relax.
|
*/

require __DIR__.'/../vendor/autoload.php';

/*
|--------------------------------------------------------------------------
| Turn On The Lights
|--------------------------------------------------------------------------
|
| We need to illuminate PHP development, so let us turn on the lights.
| This bootstraps the framework and gets it ready for use, then it
| will load up this application so that we can run it and send
| the responses back to the browser and delight our users.
|
*/

$app = require_once __DIR__.'/../bootstrap/app.php';

/*
|--------------------------------------------------------------------------
| Run The Application
|--------------------------------------------------------------------------
|
| Once we have the application, we can handle the incoming request
| through the kernel, and send the associated response back to
| the client's browser allowing them to enjoy the creative
| and wonderful application we have prepared for them.
|
*/

$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);

$response = $kernel->handle(
    $request = Illuminate\Http\Request::capture()
);

$response->send();

$kernel->terminate($request, $response);

rin4ik's avatar

@vikdhr oh man. it will never work sorry. your project name is this http://localhost:8000. I didn't think about it. your project works fine don't worry. it is just full path that's way it works http://localhost/lvoffc/index.php/login. you can't remove here index.php it is full path. if you are using php artisan serve all your routes begins with http://localhost:8000 it is your home route in this case index.php excluded. you login route http://localhost:8000/login your register route is this http://localhost:8000/register and so on. forget about your project name. if you are using homestead or valet you can name your project as lvoffc.test and then you can go to this route lvoffc.test/login. for now use just http://localhost:8000 as the name of your project

1 like
tonnikrava's avatar

This is my header of main template file in blade

@php $url = $_SERVER['REQUEST_URI'];

$rep_url = str_replace('/index.php', '', $url); if($url!==$rep_url) { header('HTTP/1.1 301 Moved Permanently'); header('Location: /'.ltrim($rep_url, '/')); exit(); } @endphp

!DOCTYPE html html lang="ru"

Please or to participate in this conversation.