How to Remove Public From URL in Laravel

How to Remove Public From URL in Laravel

Laravel removes the public path from URL; In this tutorial, we will learn how to remove the public path from URL in laravel apps using .htaccess and server.php file.

How to Remove Public From URL in Laravel 7, 8, 9

There are two ways to remove the public path from URL in laravel 7, 8, 9 apps; is as follows:

  • Solution 1 – Using .htaccess file
  • Solution 2 – Rename server.php and move .htaccess file

Solution 1 – Using.htaccess file

To create and update the .htaccess file in the Laravel. You can find .htaccess file in root directory.

You must have mod_rewrite enable on your Apache server. The rewrite module is required to apply these settings. You also have enabled .htaccess in Apache virtual host for Laravel.

Update the code into your .htaccess file:

<IfModule mod_rewrite.c>
   RewriteEngine On 
   RewriteRule ^(.*)$ public/$1 [L]
</IfModule>

Solution 2 – Rename server.php and move .htaccess file

Follow the below steps for remove public from url in laravel

  1. The first step is, Rename server.php in your Laravel root folder to index.php
  2. Copy the .htaccess file from /public directory to your Laravel root folder.

Conclusion

In this tutorial remove the public from URL in laravel. Here you have learned two ways to remove the public from URL in laravel.

Recommended Laravel Tutorials

Recommended:-Laravel Try Catch

AuthorAdmin

My name is Devendra Dode. I am a full-stack developer, entrepreneur, and owner of Tutsmake.com. I like writing tutorials and tips that can help other developers. I share tutorials of PHP, Python, Javascript, JQuery, Laravel, Livewire, Codeigniter, Node JS, Express JS, Vue JS, Angular JS, React Js, MySQL, MongoDB, REST APIs, Windows, Xampp, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL and Bootstrap from a starting stage. As well as demo example.

Leave a Reply

Your email address will not be published.