How to Remove Public From Laravel URL (4 Easy Methods)

By Kennedy Dzigbenyo | Last updated on January 2, 2026

Fix Laravel URLs: Remove Public from Your Website Address

When you install Laravel on your server or localhost, you might notice that your project URL includes /public, like this:

http://example.com/public

This happens because Laravel places its main entry point inside the public folder for security reasons. However, having /public in the URL looks unprofessional and is not user-friendly.

In this guide, I’ll show you step-by-step how to remove /public from your Laravel URL properly and securely.

Suggested Reading: How to Deploy Laravel Project on cPanel

Why Does Laravel Include the /public Directory in the URL?

Laravel is designed with security in mind. The public directory is the only folder that should be directly accessible by users because it contains the front-facing assets like CSS, JavaScript, and index.php. Meanwhile, the rest of the Laravel application (controllers, models, views, and configuration files) remains secure outside the web root to prevent direct access.

Now, let’s dive into different methods to remove /public from your Laravel URL.

A quick but risky way to remove /public from the URL is to move all files inside the public folder directly into your root Laravel directory. However, this method is not recommended because it exposes your application files to potential security threats.

If you still want to proceed, follow these steps:

  1. Move everything inside the public folder (except .htaccess) to the root folder.
  2. Open the index.php file and modify these lines:
require __DIR__.'/../bootstrap/autoload.php';
$app = require_once __DIR__.'/../bootstrap/app.php';

Change them to:

require __DIR__.'/bootstrap/autoload.php';
$app = require_once __DIR__.'/bootstrap/app.php';

⚠ Warning: While this works, it is not safe because it exposes critical Laravel directories like routes, storage, and config to the public. Avoid using this method unless absolutely necessary.

The best way to remove /public from your Laravel URL is by using an .htaccess file. This method is safe and works well on shared hosting environments like cPanel.

Steps to Use .htaccess to Remove /public from URL

  • Create or edit the .htaccess file in the root Laravel folder.
  • Add the following rewrite rules:
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
  • Save the file and upload it to your server (if applicable).

Now, when you visit http://example.com, it will automatically serve the Laravel application without requiring /public in the URL.

Method 3: Change the Document Root in cPanel or Apache Configuration

If you have full control over your hosting environment (such as VPS or Dedicated servers), a cleaner solution is to change your server’s document root to the public folder.

For cPanel Users

  1. Log into cPanel and go to Domains > Manage.
  2. Locate your domain and find the Document Root section.
  3. Change the document root from /home/youruser/public_html/ to /home/youruser/public_html/public.
  4. Save the changes and restart Apache if necessary.

For Apache Users (VPS/Dedicated Server)

  1. Open your Apache configuration file (httpd.conf or your virtual host file).
  2. Find the <VirtualHost> block for your domain and update the DocumentRoot:
DocumentRoot "/var/www/html/public"
<Directory "/var/www/html/public">
    AllowOverride All
    Require all granted
</Directory>
  1. Save the file and restart Apache:
sudo systemctl restart apache2

For Nginx Users

  1. Open your Nginx configuration file:
sudo nano /etc/nginx/sites-available/default
  1. Change the root directive:
root /var/www/html/public;
  1. Save the file and restart Nginx:
sudo systemctl restart nginx

This method ensures that your Laravel app loads correctly without needing an .htaccess workaround.

Another clean way to remove /public is by creating a symbolic link that points the public_html folder to the Laravel public directory.

  1. Backup your current html directory:
mv html html_backup
  1. Create a symbolic link from html to Laravel’s public folder:
ln -s /home/youruser/laravel_project/public /home/youruser/html
  1. Verify the symbolic link:
ls -l /home/youruser/html

This approach keeps your Laravel structure intact while making the public files accessible through html.

Conclusion

Removing /public from your Laravel URL is essential for a professional-looking and user-friendly website. Depending on your hosting setup, you can use:

.htaccess Rewrite Rules – Best for shared hosting and quick fixes.
Changing Document Root – Ideal for cPanel, VPS, or dedicated servers.
Creating a Symbolic Link – Useful for keeping Laravel’s structure clean.

Avoid moving files out of the public directory, as it poses security risks.

I hope this guide helps you set up your Laravel project the right way! If you have any questions, reach out to Aveshost support or drop a comment below. 🚀

Happy Coding!

Suggested Reading:

FAQs on How to Remove /public from Laravel URL

Why does Laravel include /public in the URL by default?

Laravel includes /public in the URL for security reasons. The public directory is the only folder that should be directly accessible by users because it contains front-facing assets like CSS, JavaScript, and index.php, while keeping the rest of the application (controllers, models, views, configuration) secure outside the web root.

What is the recommended method to remove /public from Laravel URL on shared hosting?

The recommended method for shared hosting is using an .htaccess file. Create or edit the .htaccess file in the root Laravel folder and add rewrite rules to redirect all requests to the public directory, which safely removes /public from the URL without exposing application files.

How can I remove /public from Laravel URL by changing the document root?

You can change the document root to point directly to the public folder. In cPanel, go to Domains > Manage and update the document root to include /public. For Apache or Nginx servers, modify the configuration file to set the document root to the public directory and restart the web server.

Is moving public folder contents to root directory a safe method?

No, moving public folder contents to the root directory is not recommended and poses security risks. This method exposes critical Laravel directories like routes, storage, and config to public access, making your application vulnerable to attacks. It should only be used as a last resort.

What is the symbolic link method for removing /public from URL?

The symbolic link method involves creating a link that points your web server’s document root (like public_html) to Laravel’s public directory. This keeps the Laravel structure intact while making public files accessible without /public in the URL. It’s a clean solution for advanced users with server access.

Kennedy Dzigbenyo

About Author

Kennedy Dzigbenyo is a dedicated Software Engineer and WordPress Expert whose expertise lies in turning conceptual digital dreams into tangible realities. He excels in the art of creating digital solutions that respond to contemporary needs.