ItSolutionStuff.com

How to Remove Public from URL in Laravel 10?

By Hardik Savani • November 5, 2023
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

.htaccess

<IfModule mod_rewrite.c>

RewriteEngine On

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

</IfModule>

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...

Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

Laravel 10 Image Validation Rule Example

Read Now →

Laravel 10 Custom Login and Registration Example

Read Now →

Laravel 10 Custom Forgot Password Example

Read Now →

Laravel 10 Email Verification Tutorial Example

Read Now →

Laravel 10 Send SMS using Twilio Tutorial Example

Read Now →

Load More Data on Button Click using JQuery Laravel 10

Read Now →

Laravel 10 Store Backup on Dropbox using Spatie Tutorial

Read Now →

Laravel 10 Many to Many Eloquent Relationship Tutorial

Read Now →

Laravel 10 Scout Full Text Search Tutorial

Read Now →

Laravel 10 JQuery UI Ajax Autocomplete Search Example

Read Now →

How to Get Last Executed Query in Laravel 10?

Read Now →

Laravel 10 Select2 Ajax Autocomplete Search Example

Read Now →

Laravel 10 Ajax Request Example Tutorial

Read Now →

Laravel 10 Multiple File Upload Tutorial Example

Read Now →