Remove public from Laravel url

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

Step 2: Copy .htaccess file form public directory

In second step you just need to copy .htaccess file from public folder.

Step 3: Update code in .htaccess file

In third step you need to update code of copied .htaccess file in second step like below

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 4: Upload .htaccess file to Laravel root folder

In fourth step you need to upload updated .htaccess file to Laravel root folder.

Leave a Reply