Remove /public from URL in Laravel Project – Best Methods for Clean URLs
In this post, you’ll learn how to remove /public/ from your Laravel URL using three effective methods. We’ll cover local development, production hosting, and some gotchas to avoid.

If you’re building a Laravel app and see URLs like http://example.com/public/
, you're not alone. Laravel routes through the public/
directory by default for security reasons, but it’s totally possible (and clean) to remove /public/
from the URL.
Why Laravel Uses /public
in URLs
Laravel’s public/
folder acts as the entry point for the application. It keeps your core code (app/
, routes/
, .env
) safe from public access by routing all web traffic through a single secure location: public/index.php
.
While this is great for security, it’s not ideal for clean URLs.
Method 1: Move Files from /public to Root (Not Recommended for Production)
This method involves moving key files from /public
to your Laravel root.
Steps:
Move these files from
public/
to your root:index.php
.htaccess
Open the
index.php
file and update the paths:
⚠️ Warning: This exposes your app to potential risks. Only use this for temporary setups or local experiments.
Method 2: Use a Virtual Host (Recommended)
The best and secure method is to configure a virtual host that points directly to the public/
directory.
- Virtual Host Config in Apache (XAMPP, WAMP, or VPS):
Then:
Add
127.0.0.1 laravel.test
to your/etc/hosts
orC:\Windows\System32\drivers\etc\hosts
Restart Apache
You can now visit your app at http://laravel.test
without /public
.
- Nginx (Bonus Tip)
Point the root
to public/
in your site config:
Method 3: Redirect Using .htaccess
If you can’t set up virtual hosts (like on shared hosting), use an .htaccess
file in your Laravel root:
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 isn’t a clean solution—it just forwards requests to public/
, but the URL won’t show it.
Which Method is Best?
Method | Best For | SEO Friendly | Secure |
---|---|---|---|
Move Files | Quick demo | ❌ | ❌ |
Virtual Host | Local & production | ✅ | ✅ |
.htaccess | Shared hosting | ⚠️ Partial | ⚠️ Partial |
Use virtual hosts or server configs for professional and production-grade setups.
Related Resources
FAQ
Q: Why not just delete the public/
folder?
Because Laravel uses index.php
in public/
to bootstrap the app securely. Removing it breaks the routing and exposes critical files.
Q: Is it safe to move index.php to root?
Only for local testing. In production, it’s insecure and not recommended.
Q: How to set up Laravel Valet to remove /public
?
Valet automatically serves from the public/
directory. Just run valet link
in your project folder.
Conclusion
Removing /public/
from your Laravel URL isn’t just about aesthetics—it’s about serving your app cleanly and securely.
For best results, use virtual hosts or Nginx/Apache config to serve from the public/
folder directly.