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

teampoison's avatar

Laravel Showing Index.php How can I Remove This

Root htaccess

RewriteEngine On


#----------------------------------------------
# | this code use for remove public directory |
#----------------------------------------------




RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ / [L,R=301]
RewriteCond %{REQUEST_URI} !(\.ico|\.css|\.js|\.png|\.jpg|\.gif|robots\.txt|\.eot|\.svg|\.ttf|\.woff|\.woff2|\.otf|\.pdf)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/public/
RewriteCond %{REQUEST_URI} !^/public/uploads
RewriteRule ^(login|uploads|assets|css|js|images|ca|favicons|fonts|)/(.*)$ public// [L,NC]


RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(.*)$ /public/ [L,QSA]

Public Folder htaccess

<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
12 replies
LaryAI's avatar
Level 58

In your root .htaccess file, you need to remove the following lines:

RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(.*)$ /public/ [L,QSA]

Then, in your public .htaccess file, you need to add the following line:

RewriteBase /

This should remove the index.php from the URL.

webrobert's avatar

You are pointing your site to the wrong directory. You are pointing to ‘yourcoolsite’ but you should point the site to ‘yourcoolsite/public’

webrobert's avatar

@teampoison where ever you setup your hosting you chose a directory to point the site to. That’s what to change.

Snapey's avatar

@teampoison its called the document root and needs to point to the public folder. Instructions vary by web server type and if running something like cpanel

webrobert's avatar

@teampoison I don’t know how else to say it. Your site points to the wrong folder. This is a common mistake. You don’t need to delete files or edit configs. Point the site to the correct folder….

-> ‘ LaravelProjectdirectoy/public’

jlrdw's avatar

@teampoison Why don't you just point to public as document root. Move main laravel out of web. And this has actually been discussed here many times on how to setup laravel on shared host.

If APache, their site also has how to articles.

If Nginx, the laravel documentation covers it.

Tray2's avatar

@teampoison like so many here have told you, you need to change the document root on the web server.

This can either be done by changing the domains config files directly or by doing it in Cpanel.

https://support.cpanel.net/hc/en-us/articles/360055211213-How-to-change-the-document-root-of-the-primary-domain

If you want to change it manually you need to know which http server you are running, the most common ones are apache2 and hginx.

https://stackoverflow.com/questions/5891802/how-do-i-change-the-root-directory-of-an-apache-server

https://serverfault.com/questions/604306/how-do-i-change-the-root-path-in-nginx

Please or to participate in this conversation.