Laravel 9 - Remove Public from URL using htaccess
Jul 29, 2022 . Admin
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.
Step 1: Rename FileIn 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.phpStep 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:
.htaccessOptions -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]
Ok, now you can run and check it.
It will help you...