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 html string in blade in laravel

How to Render Html String in Blade in Laravel ?

March 8, 2022December 2, 2023

Blade is a template engine to write the syntax easily and powerfully. To render html string in blade in laravel we use {!! $htmlstring !!}. Using the blade template we can easily print a variable, can create loops and can create directives and components too. Laravel blade template uses filename.blade.php…

Read More
Php How to use limit query in Laravel Eloquent

How to use limit query in Laravel eloquent query with example

February 5, 2022October 4, 2022

Limit clause is used to restrict the number of rows return in executed query. It’s quite useful when working with large data set since querying the large data creates performance issues so to overcome with the large dataset issue we use limit clause in a query. Laravel Limit clause accepts…

Read More
Laravel Get Today Records in Laravel

How to Get Today Records in Laravel ?

November 17, 2023March 16, 2024

In this blog post we will learn to get today records in laravel. we will use carbon and whereDate method of laravel eloquent to fetch the today records. In laravel models save the data in column created_at and created_at column stores the date time but if we want to fetch…

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

  • 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

  • Mastering Schedule Management with Laravel Zap
  • 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
©2023 Readerstacks | Design and Developed by Readerstacks
Go to mobile version