Share this:

Today, we are going to learn Laravel 9 Remove Public from URL using htaccess. In this tutorial we are going to cover on how to remove public form the url using htaccess.

In this example, you will learn laravel remove public from url. you will learn laravel .htaccess to remove public from url. step by step explain remove public from url in laravel. This post will give you simple example of how to remove public from url in laravel using htaccess.

Actually I had also problem in my laravel 9 application and i need to upload it in GoDaddy shared hosting. I remove public from url path using .htaccess and server.php file. You have to just two step and you can also done with your laravel 9 application. So let’s do it.

Steps for Laravel 9 Remove Public from URL using htaccess:

  • Step 1: Rename File
  • Step 2: Update .htaccess
  • Step 3: Conclusion

Also Read: Laravel 9 User Roles and Permissions Tutorial Example

Step 1: Rename File

In first step it is very easy and you need to just rename file name. you have to rename server.php to index.php at your laravel root directory.

server.php
INTO
index.php

Also Read: How to Use Inner Join In Laravel 9

Step 2: Update .htaccess

First of all you have to copy .htaccess file and put it laravel root folder. You just copy .htaccess file from public folder and then update bellow code:

.htaccess

Options -MultiViews -Indexes
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_URI} !(\.css|\.js|\.png|\.jpg|\.gif|robots\.txt)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(css|js|images)/(.*)$ public/$1/$2 [L,NC]

Step 3: Conclusion

Today, We had learn Laravel 9 Remove Public from URL using htaccess. Hope this tutorial helped you with learning Laravel 9. If you have any question you can ask us at comment section below. If you like the tutorial please subscribe our YouTube Channel and follow us on social network Facebook and Instagram.

Also Read: Laravel 9 Get env Variable in Blade File Example

Share this:

Categorized in: