Laravel 5 – Remove Public from URL

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

    Even if i do not recommend putting Laravel on the root folder there are some cases when it could not be avoided; for those cases the above methods do not work for assets so i made a quick fix changing the htaccess: after copying server.php to index.php edit the .htaccess file like so:

    
        
            Options -MultiViews
        
    
        RewriteEngine On
    
        ### fix file rewrites on root path ###
        #select file url
        RewriteCond %{REQUEST_URI} ^(.*)$
        #if file exists in /public/
        RewriteCond %{DOCUMENT_ROOT}/public/$1 -f
        #redirect to /public/
        RewriteRule ^(.*)$ public/$1 [L]
        ###############
    
        # Redirect Trailing Slashes If Not A Folder...
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule ^(.*)/$ /$1 [L,R=301]
    
        # Handle Front Controller...
    
        #RewriteCond %{REQUEST_FILENAME} -d # comment this rules or the user will read non-public file and folders!
        #RewriteCond %{REQUEST_FILENAME} -f #
        RewriteRule ^ index.php [L]
    
    

    This was a quick fix i had to make so anyone is welcome to upgrade it.

提交回复
热议问题