Tutorial Details

How to Remove Public from URL in Laravel 10
04 Nov

How to Remove Public from URL in Laravel 10

Hi Guys,

This article goes into detail on how to remove the public from url in Laravel 10. you can see remove public from URL Laravel 10 using htaccess. This example will help you remove the public from the 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 the public from the URL.

Sometimes we upload Laravel application code on shared hosting and you want to run it. Then we can not set a direct path of index.php with shared hosting. so we just need to run the app with a "public" folder. so, you will face an issue with "public" in url. here, I will give you two solutions on how to remove the public from url in the Laravel application.

I will suggest you don't have to use "shared hosting" for the 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 the Apache virtual host to use it in Laravel.

Finally, Just go to the root folder create a .htaccess file, and upload it with the 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 files move to the root folder.

I hope this can help you...

0 Comments

Leave a Comment