How to Remove /public Prefix from URL in Laravel using htaccess

Learn how to remove the /public prefix from a Laravel URL using an .htaccess file.

How to Remove /public Prefix from URL in Laravel using htaccess

October 3, 2024

If you're using Laravel on a hosting service that doesn't allow changing the document root, you'll encounter the issue of having /public in your URLs.

 

To resolve this issue, create an .htaccess file and add the following directives:

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

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

 

No additional configuration is required.