ads


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 127.0.0.1 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 

Here I give example for fresh installation laravel you can learn what I did and used into your existing laravel project one by one step you need to follow for setting up your perfect laravel domain if you using fresh installation laravel it is easily working but when you work on your existing laravel project please read carefully then apply the same rules into your project because it will maybe create the problem on your server like may blank page or not access error will show on your server link if you are not following the perfect step by step rules here.

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
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=root

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
</IfModule>

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

</IfModule>



Remove public/index.php from URL 

Step:1 update .htaccess file only

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


Read This Carefully

once you applied this it will solve just remove public or index.php from your laravel but it will also create problem-related to CSS, js not found in the console area you can check there also there will throw an error with a red line if there is a new laravel then it will app.css and app.js not found because it is connected with a public path and we'll remove that path once you replace the .htaccess file as I defined above the file

---->Shortly you can write this type of syntax and the problem will be solved.

into <head> tag
<link rel="stylesheet" href="{!! asset('app.css') !!}"> 

into <body> tag
<script src="{!! asset('app.js) !!}"></script>

remember I'll above write about simple laravel first fresh installation code example.

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

أحدث أقدم