Laravel 5 – Remove Public from URL

后端 未结 30 2033
甜味超标
甜味超标 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:47

    Here is the Best and shortest solution that works for me as of may, 2018 for Laravel 5.5

    1. just cut your .htaccess file from the /public directory to the root directory and replace it content with the following code:

      
          
             Options -MultiViews
          
      
          RewriteEngine On
      
          RewriteCond %{REQUEST_FILENAME} !-d
          RewriteRule ^(.*)/$ /$1 [L,R=301]
      
          RewriteCond %{REQUEST_URI} !(\.css|\.js|\.png|\.jpg|\.gif|robots\.txt)$ [NC]
          RewriteCond %{REQUEST_FILENAME} !-d
          RewriteCond %{REQUEST_FILENAME} !-f
          RewriteRule ^ server.php [L]
      
          RewriteCond %{REQUEST_FILENAME} !-d
          RewriteCond %{REQUEST_FILENAME} !-f
          RewriteCond %{REQUEST_URI} !^/public/
          RewriteRule ^(css|js|images)/(.*)$ public/$1/$2 [L,NC]
      
      
    2. Just save the .htaccess file and that is all.

    3. Rename your server.php file to index.php. that is all enjoy!

提交回复
热议问题