How to Remove Public from URL in Laravel 10?

How to Remove Public from URL in Laravel 10? In this tutorial, we will learn how to remove the public path from URL in Laravel 10 apps using .htaccess and server.php file.

How to Remove public From URL in Laravel 10?

There are two solution to remove the public/index.php path from URL in Laravel 10 apps; is as follows:

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

Solution 1: 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.

Solution 2: 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>

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.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top