How to Remove Public from URL in Laravel 10?

By Hardik Savani November 5, 2023 Category : Laravel

Hi Dev,

This article goes in detailed on how to remove public from url in laravel 10. you can see remove public from url laravel 10 using htaccess. This example will help you remove public from url in laravel 10 with htaccess. In this article, we will implement a remove public from laravel 10 htaccess. you will do the following things for laravel 10 remove public from url.

Sometime we upload laravel application code on shared hosting and you want to run it. Then we can not set directly path of index.php with shared hosting. so we must need to run app with "public" folder. so, you will face issue with "public" in url. here, i will give you two solution how to remove public from url in laravel application.

I will suggest you don't have to use "shared hosting" for laravel application and never go for this solution.

Solution 1: Laravel Remove Public From URL using .htaccess

In Laravel, the .htaccess file can be generated and edited to incorporate new changes. The .htaccess file is located in the root directory, and its modification requires mod_rewrite to be enabled on your Apache server. It is mandatory to enable the rewrite module to implement these changes. Moreover, you need to activate .htaccess in Apache virtual host to use it in Laravel.

Finally, Just go to root folder and create .htaccess file and upload with following code


<IfModule mod_rewrite.c>

RewriteEngine On

RewriteRule ^(.*)$ public/$1 [L]


Solution 2: Rename server.php and Move .htaccess File

To remove "public" from your Laravel URL, you need to complete the following two steps:

1. Rename the server.php file in your Laravel root folder to index.php.

2. Copy the .htaccess file located in the /public directory to your Laravel root folder.

3. All public folder css and js file move to root folder.

I hope it can help you...