What's new

Welcome to adpde | Welcome My Forum

Join us now to get access to all our features. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, and so, so much more. It's also quick and totally free, so what are you waiting for?

Methods to Take away ‘Public’ from URL in Laravel PHP Framework?


Staff member
Mar 22, 2024
Reaction score
When deploying a Laravel software on shared internet hosting, you could encounter the widespread difficulty of the “public” folder showing in your web site’s URL. This will make your URLs much less elegant and user-friendly. On this tutorial, we’ll discover two efficient options to take away “public” from the URL in Laravel 10.

Why Take away ‘Public’ from Laravel URL?​

Earlier than we dive into the options, it’s important to grasp why we have to take away “public” from the Laravel URL. If you add a Laravel software to shared internet hosting, you typically can’t set the trail on to the index.php file. Consequently, it’s essential to run the applying from the “public” folder, which may result in URLs like yourwebsite.com/public/index.php. That is removed from best, and we’ll present you methods to clear it up.

Resolution 1: Eradicating ‘Public’ Utilizing .htaccess​

In Laravel, the .htaccess file performs an important function in URL rewriting and can be utilized to get rid of “public” out of your URLs. Observe these steps:

  • Create a New .htaccess File: Go to the foundation folder of your Laravel software and create a brand new .htaccess file.
  • Edit .htaccess: Open the newly created .htaccess file and add the next code:

<IfModule mod_rewrite.c>
   RewriteEngine On 
   RewriteRule ^(.*)$ public/$1 [L]
  • Save and Add: Save the modifications and add the .htaccess file to the foundation listing of your Laravel software.

This .htaccess code makes use of Apache’s mod_rewrite module to redirect all requests to the “public” folder, successfully eradicating “public” from the URL.

Resolution 2: Rename server.php and Transfer .htaccess​

To additional clear up your Laravel URLs, comply with these steps:

  1. Rename server.php: In your Laravel root folder, rename the server.php file to index.php.
  2. Transfer .htaccess: Find the .htaccess file throughout the /public listing of your Laravel software. Copy it and paste it into your Laravel root folder.
  3. Transfer Property: In case your software has CSS and JS recordsdata within the “public” folder, transfer them to the foundation folder as effectively. You’ll want to replace the references to those property in your views and layouts.

These steps successfully route all incoming requests to the index.php file and streamline your URLs.


Eradicating “public” out of your Laravel 10 software’s URL is a vital step to make your web site URLs extra user-friendly. You may select between utilizing a .htaccess file or renaming recordsdata and shifting the .htaccess for attaining this objective. By following these options, your Laravel software may have cleaner, extra professional-looking URLs, enhancing person expertise and search engine marketing rankings.
Top Bottom