Remove Public from Laravel URL

  1. Rename server.php file to index.php file at laravel root
  2. Copy the .htaccess from public folder to root folder.
  3. Replace .htaccess content that copied in 2nd step as follows



    
        Options -MultiViews
    

    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 ^(admin|css|js|images|uploads)/(.*)$ public/$1/$2 [L,NC]


Add new folder or file extensions as required in your project!


3 comments

Neeraj

This is great post!

Neeraj

Hi greate answer!

hemant

sir ji , awesome documentation

Post comment Comments (3)