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

Published on October 3, 2024. Last updated on January 22, 2025.
How to Remove /public Prefix from URL in Laravel using htaccess

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.