Laravel Remove Public from URL

To remove public from url in laravel apps; Through this tutorial, i am going to show you how to remove public from url using .htaccess and without .htaccess file in laravel 7, 8, 9 apps.

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

Now, i am going to show you two simple solution to remove public path from url in laravel 9, 8, 7 apps; is as follows:

  • Solution 1 – Using .htaccess
  • Solution 2 – Without using .htaccess

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 9, 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 9, 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.
  • And Rename server.php in your Laravel root folder to index.php
  • Then copy the .htaccess file from /public directory to your Laravel root folder.

Recommended Laravel Tutorials

Be First to Comment

Leave a Reply

Your email address will not be published.