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

DDSameera's avatar

Laravel 8 URL is not working without index.php

Hello Genius,

Please help me to resolve this . I hosted Laravel application on production environment. Now i got following issue .

Not Working http://boobamba.com/samadhi/stts/public/login

Working fine http://boobamba.com/samadhi/stts/public/index.php/login

htaccess file

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

    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]

    # Send Requests To Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

0 likes
21 replies
DDSameera's avatar

@jlrdw , this is VPS server not shared one.

Here is my URL Structure

www.boobamba.com/samadhi/lms www.boobamba.com/manchi/lms www.boobamba.com/oxford/lms

lms is laravel web folder . samadhi , machin,oxfords are company names.

jlrdw's avatar

See my updated reply above, have you modified anything in public?

jlrdw's avatar

You can try the following, leave laravel's original htaccess alone however.

Add another .htaccess with only this to base root like lms

    RewriteEngine On
    RewriteRule ^(.*)$ public/
    RewriteRule ^ server.php

That will serve public, and in public you should have this .htaccess:

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

    RewriteEngine On
    RewriteBase /yoursite/  I only add this line try /lms/

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

    # Send Requests To Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
    # RewriteRule ^(.*)$ public/ [L]
</IfModule>

I like adding the RewriteBase /yoursite/ so I don't need all the extra slashes in routing and redirecting.

Of course yoursite gets changed to actual url root of site.

jlrdw's avatar

If main laravel is not out of the webroot, you should leave public alone and use as designed, otherwise you have an insecure set up.

I would suggest setting up a temp app, and experiment around with what works and what doesn't work for you.

Right now at the end of your url if you type .env does it show your private environment file? It shouldn't if set up correctly.

1 like
DDSameera's avatar

@jlrdw , you are right. i can see ".env" file information. (www.boobamba.com/samadhi/lms/.env) Okay i will setup laravel app as it is . my question , how could i remove "index.php" file from this url . it doesn't work :(

Please note : mod_rewrite module also enabled in my centos7 server

DDSameera's avatar

@jlrdw , Now i created this URL Structure. Also i kept public folder as it is . however i can see .env file through this link www.boobamba.com/samadhi/.env

Here is my project url

http://boombamba.com/samadhi/

Here is my UPDATED project folder structure. https://snipboard.io/hTxaiA.jpg

jlrdw's avatar

how could i remove "index.php"

By using the second .htaccess I showed.

It correctly points to public as webroot, there in public is index.php and Laravel's .htaccess which do their thing.

Just how many levels deep is public?

You need to tell index.php where to find main laravel via adjusting:

/../../../../../../  // however many you need.

Like

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

If setup correct, you do not have to adjust index.php at all.

DDSameera's avatar

@jlrdw - Just how many levels deep is public?

01

do i need to apply this for other places

<?php

use Illuminate\Contracts\Http\Kernel;
use Illuminate\Http\Request;

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

/*
|--------------------------------------------------------------------------
| Check If Application Is Under Maintenance
|--------------------------------------------------------------------------
|
| If the application is maintenance / demo mode via the "down" command we
| will require this file so that any prerendered template can be shown
| instead of starting the framework, which could cause an exception.
|
*/

if (file_exists(__DIR__.'/../storage/framework/maintenance.php')) {
    require __DIR__.'/../storage/framework/maintenance.php';
}

/*
|--------------------------------------------------------------------------
| Register The Auto Loader
|--------------------------------------------------------------------------
|
| Composer provides a convenient, automatically generated class loader for
| this application. We just need to utilize it! We'll simply require it
| into the script here so we don't need to manually load our classes.
|
*/

require '/var/www/html/samadhi/vendor/autoload.php';

/*
|--------------------------------------------------------------------------
| Run The Application
|--------------------------------------------------------------------------
|
| Once we have the application, we can handle the incoming request using
| the application's HTTP kernel. Then, we will send the response back
| to this client's browser, allowing them to enjoy our application.
|
*/

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

$kernel = $app->make(Kernel::class);

$response = tap($kernel->handle(
    $request = Request::capture()
))->send();

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

jlrdw's avatar

Above just examples, stick with the default levels.

DDSameera's avatar
DDSameera
OP
Best Answer
Level 3

@jlrdw Highly appreciate your effort at this moment.

I forgot to tell some thing . I m using Centos 7 production server. So @putheakhem , highlighted the vhost scenario. so i setup vhost and configuer it with my domain.

Solution Setup vhost in VPS server

Documentation https://linuxize.com/post/how-to-set-up-apache-virtual-hosts-on-centos-7/

After that everything has been resolved.

Now i can access without index.php URL

Thanks again for your time and effort. !!

Snapey's avatar

The only correct way to do this is to serve the public folder as the document root

Anything else is a hack

1 like
DDSameera's avatar

100% Agree with you @snapey . I saw so many articles guide to change server.php name into index.php , bla bla...that is damn wrong thing.

iamputhea's avatar

It is customized. I wouldn't suggest doing that. Please follow the best practice in laravel framework. Then you don't get stressed.

Please or to participate in this conversation.