Remove /public from URL in laravel project using .htaccess (Shared Hosting Tip)

If you're deploying your Laravel project on shared hosting, you might see your app loading only from yourdomain.com/public. Here's a quick and clean fix using .htaccess to remove /public from the URL.

Remove /public from URL in laravel project using .htaccess (Shared Hosting Tip) Image

Laravel .htaccess for Shared Hosting

Use this .htaccess file place it in your Laravel root folder:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^$ public/index.php [L]
    RewriteRule ^((?!public/).*)$ public/$1 [L,NC]
</IfModule>

This will silently rewrite all your base URIs to the /public folder. Even all Headers, for example the HTTP Authorization Header, and all optional URI parameters will silently be passed on to the /public folder as well.

This redirects all requests to the public folder without showing /public in the URL.

You can find another way here

Final Notes

  • Works great on cPanel and other shared hosting environments.

  • No need to modify server configs or use a custom domain path.

  • Ideal when you can’t change document root on shared hosting.

Do you Like?