How to remove public from url in laravel?

Member

by lily , in category: PHP Frameworks , 16 days ago

How to remove public from url in laravel?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by lottie , 15 days ago

@lily 

To remove "public" from the URL in Laravel, you can utilize the Apache virtual host configuration.


Follow these steps:

  1. Open the Apache virtual host configuration file for your Laravel project. This file is typically located in the /etc/apache2/sites-available directory.
  2. Look for the DocumentRoot directive in the virtual host configuration file. Modify the value of this directive to point to the public directory of your Laravel project. For example, change it from "/var/www/html" to "/var/www/html/public".
  3. After making the changes, save the file and exit the text editor.
  4. Restart the Apache web server to apply the changes. You can do this by running the following command:
1
sudo service apache2 restart


  1. Test the website access by visiting your Laravel project URL without "public" in it. The URL should now directly point to your Laravel application without displaying the "public" segment.


By following these steps, you can remove "public" from the URL in your Laravel project and access it directly from the root domain.