How to Remove Public Path from URL in Laravel

The easiest way to remove public/index.php path from URL in Laravel 11, 10, 9, 8, 7 apps is to create Index.php in the root directory and copy the .htaccess file from the public directory to the root directory.

How to Remove Public/index.php From URL in Laravel 11, 8, 7

The simple two solutions to remove public/index.php path from url in Laravel 11, 10, 9, 8, 7 apps:

Solution 1 – Using .htaccess

First of all, visit your laravel app root directory and create one file nemed .htaccess. Then add the following code into it to remove public from url in Laravel 11, 8, 7 apps; is as follows:

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

Note that :- 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.

Solution 2 – Without using .htaccess

To remove public path from url in Laravel 11, 8, 7 apps. So, you can use the below given steps and remove public from url in laravel apps; is as follows:

  • Visit to your laravel app root directory.
  • Create index.php in your Laravel root folder
  • Copy the .htaccess file from /public directory to your Laravel root folder.

Recommended Laravel Tutorials

Leave a Comment