Here in this tutorial, I'll show you that is a major problem - How to remove public/index.php from URL into the laravel framework. First, you can install the laravel as I defined command into the first step of the tutorial and then follow the exact same steps as I write here for you. This is an issue only come If you will install laravel first time on your PC and this is the first basic requirement to start laravel framework with proper URL, not with the public or public/index.php

I know one way there is you can run this command - php artisan serve and you can see the link will like this but when you upload you full project to your personal hosting then you must follow this tutorial for laravel setup URL without public or index.php 

Eg. suppose you install laravel first time you can see your directory paths like /var/www/html/blog and the URL will http://localhost/blog/public or http://localhost/blog/public/index.php so it is not a good URL for our projects and our projects url is also the same as the domain. not domain+public or index.php 

You can follow my tutorial steps and solve your laravel basic problem when you install first time laravel.

Remove Public from URL

Laravel - Remove Public from URL 

Remove public/index PHP from Laravel url follow below steps

Step:1 Install Latest Laravel using the below command

first of all, we need to get a fresh Laravel latest version application using bellow command, So open your terminal OR command prompt and run bellow command:
-composer create-project --prefer-dist laravel/laravel blog

Step:2 setup your database configuration using .env file

Step:3 Rename File

this is so important steps for setup do not forget to rename this file from your root main laravel (blog) folder where you installed the laravel latest project using the first steps

-server.php file name change to the index.php of the root folder

Step:4 Update .htaccess File

-Copy .htaccess file from public folder to Main Root Folder and update code

<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ ^$1 [N]

RewriteCond %{REQUEST_URI} (\.\w+$) [NC]
RewriteRule ^(.*)$ public/$1

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php


Remove public/index.php from URL 

Step:1 update .htaccess file only

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]

Read This Carefully

If you will get any type of trouble after removing the public from URL you can read this - How to remove public from url in Laravel using htaccess

Just follow 2 steps any type of laravel version will remove public from URL of laravel project folder

If you like my way that how to Remove public from laravel 7 you can like and share this blog and comment also

Thank you.

Post a Comment

Previous Post Next Post