Laravel 5 – Remove Public from URL

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

    I have solved the issue using 2 answers:

    1. Renaming the server.php to index.php (no modifications)
    2. Copy the .htaccess from public folder to root folder (like rimon.ekjon said below)
    3. Changing .htaccess it a bit as follows for statics:

      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 ^ index.php [L]
      
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_URI} !^/public/
      RewriteRule ^(css|js|images)/(.*)$ public/$1/$2 [L,NC]
      

      If there are any other static files needed just add the extension to the previous declared list

提交回复
热议问题