Skip to content
Readerstacks logo Readerstacks
  • Home
  • Softwares
  • Angular
  • Php
  • Laravel
  • Flutter
Readerstacks logo
Readerstacks
3 Ways to Remove public from URL in Laravel

3 Ways to Remove public from URL in Laravel

Aman Jain, August 22, 2021November 8, 2023

Laravel comes with default server for local environment and but if run the application in apache then we need to remove the public from URL because if we serve the application through the Apache then we need to call the URLs from public directory. It can be multiple way to remove the public from URL in laravel but most efficient and recommended way to remove is using virtual host and pointing virtual host to public directory of application.

We will cover all possible way to achieve Remove public from URL in Laravel and this example we will work in all laravel version laravel 5, laravel 6, laravel 7, laravel 8 and laravel 9

There is multiple options to remove the public from the URL in laravel application.

let’s have look on multiple options of removing public and which one is more secure and reliable method to use.

1. Replacing server.php to index.php

Replacing the root file server.php to index.php is easiest way to remove public from url. but this is not safe and recommended method.

you also need to copy the public/.htaccess file to root folder of the website to working it out.

2. Creating a .htaccess file on root of laravel project

Creating a new file on root of laravel .htaccess and put this below code in the file

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(.*)$ /public/$1 [L,QSA]

This code will rewrite all request to public folder silently and application will not expose to security risk.

3. Best and recommended method by laravel, creating virtual host to remove public from URL

To enable this we need to edit the apache httpd.conf or httpd-vhost.conf file.

And enter the below code to enable virtual host for the specific application.

<VirtualHost *:80>
    DocumentRoot "F:/xampp/htdocs/dev/public"
    ServerAdmin admin@localhost
    ServerName laravel.app
    ServerAlias www.laravel.app

    <Directory "F:/xampp/htdocs/laravelblog/public">
       AllowOverride All
       Options Indexes FollowSymLinks

       Require local
       # if you want access from other pc's on your local network
       #Require ip 192.168.1
       # Only if you want the world to see your site
       #Require all granted
    </Directory>
</VirtualHost>

Related

Laravel

Post navigation

Previous post
Next post

Related Posts

Php Get Json Post Data in Laravel

How to Get Json Post Data in laravel from Request ?

June 8, 2022February 8, 2024

In this article we will learn to get json post data in laravel from request. Laravel by default supports for form-data and x-www-form-urlencode which we can get easily using the Request class as follow $request->field_name or $request->get(‘field_name’). To retrieve the json post data in laravel we need to call json…

Read More
Laravel insert multiple rows in laravel

How to insert multiple rows in laravel ?

November 12, 2023March 16, 2024

Laravel supports both types of insert statement like single and multiple. In this article we will learn to insert multiple rows in laravel. Laravel, a powerful PHP framework, provides developers with a range of functionalities to streamline database operations. One common task developers often encounter is the need to insert…

Read More
Php How to Add Captcha, validate and refresh captcha in Laravel Form

How to Add Captcha, validate and refresh captcha in Laravel Form ?

March 10, 2022November 17, 2023

Captcha is used to enhance the security of form. By adding the Captcha in laravel form we can prevent attackers to submit the form using the automated scripts and it adds an extra layer of security. To add the captcha in laravel form we can use package mews/captcha, its easy…

Read More

Aman Jain
Aman Jain

With years of hands-on experience in the realm of web and mobile development, they have honed their skills in various technologies, including Laravel, PHP CodeIgniter, mobile app development, web app development, Flutter, React, JavaScript, Angular, Devops and so much more. Their proficiency extends to building robust REST APIs, AWS Code scaling, and optimization, ensuring that your applications run seamlessly on the cloud.

Categories

  • Angular
  • CSS
  • Dart
  • Devops
  • Flutter
  • HTML
  • Javascript
  • jQuery
  • Laravel
  • Laravel 10
  • Laravel 11
  • Laravel 9
  • Mysql
  • Php
  • Softwares
  • Ubuntu
  • Uncategorized

Archives

  • August 2025
  • July 2025
  • June 2025
  • May 2025
  • April 2025
  • October 2024
  • July 2024
  • February 2024
  • January 2024
  • December 2023
  • November 2023
  • October 2023
  • July 2023
  • March 2023
  • November 2022
  • October 2022
  • September 2022
  • August 2022
  • July 2022
  • June 2022
  • May 2022
  • April 2022
  • March 2022
  • February 2022
  • January 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • June 2021

Recent Posts

  • The Transformative Power of Education in the Digital Age
  • Understanding High Vulnerabilities: A Closer Look at the Week of July 14, 2025
  • Exploring Fresh Resources for Web Designers and Developers
  • The Intersection of Security and Technology: Understanding Vulnerabilities
  • Mapping Together: The Vibrant Spirit of OpenStreetMap Japan
©2023 Readerstacks | Design and Developed by Readerstacks
Go to mobile version