Laravel 5 – Remove Public from URL

后端 未结 30 2367
甜味超标
甜味超标 2020-11-22 03:20

I know this is a very popular question but I haven\'t been able to find a working solution for Laravel 5. I\'ve been trying to migrate from Codeigniter for a long time, but

30条回答
  •  时光取名叫无心
    2020-11-22 03:35

    You can simply do it in 2 easy steps

    1. Rename your server.php file in root directory of your laravel project.

    2. create a .htaccess file on root directory and paste the below code in it

    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]
    
    

提交回复
热议问题