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 How to Set and Get Cookies in Laravel

How to Set and Get Cookies in Laravel ?

July 25, 2022July 25, 2022

In this article we will learn to set and get cookies in laravel. Cookies are used to store the data in client computer, Cookie can hold tiny information in computer and can retrieve when required for same website. In laravel we can store and fetch cookies using laravel inbuilt methods…

Read More
Php Use Soft Delete to Temporary (Trash) Delete the Records in Laravel

Use Soft Delete to Temporary (Trash) Delete the Records in Laravel 9 ?

June 14, 2022June 14, 2022

Soft delete in laravel is use to hide the record from users by keeping the data in the database. In laravel we use Soft Delete to Temporary (Trash) Delete the Records. There is many purpose of soft delete like deleting the user for admin but keep all the information in…

Read More
Php How to Concat Two Columns in Laravel Eloquent Query With Search

How to Concat Two Columns in Laravel Eloquent Query With Search ?

June 22, 2022June 22, 2022

In this article we will learn to use aggregate function concat in laravel eloquent with search and query builder. Concat is used to join two columns and in laravel eloquent there is no method for concat but we can use DB builder to use native MySQL Methods. In MySQL or…

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

  • 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 Resilience of Nature: How Forests Recover After Fires
  • Understanding Laravel Cookie Consent for GDPR Compliance
  • Understanding High Vulnerabilities: A Critical Overview of the Week of May 12, 2025
  • Installing a LAMP Stack on Ubuntu: A Comprehensive Guide
  • Understanding High Vulnerabilities: A Deep Dive into Recent Security Concerns
©2023 Readerstacks | Design and Developed by Readerstacks
Go to mobile version