Laravel 5 – Remove Public from URL

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

    You can remove public keyword from url using various methods.

    1) If you are using dedicated hosting and you have root access then You can remove public keyword from url using Virtual Host. You should give DocumentRoot path with public. So this will start index from public directory and remove it from url.

    
        ServerAdmin info@example.com
        ServerName example.com
        ServerAlias www.example.com
        DocumentRoot /var/www/html/{yoursourcedirectory}/public
    
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
    
    

    2) If you dont have root access of your hosting then you should genarate a new .htaccess file in your root directory and put the code as below

    
    
        Options -MultiViews
    
    
    RewriteEngine On
    
    RewriteCond %{REQUEST_FILENAME} -d [OR]
    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule ^ ^$1 [N]
    
    RewriteCond %{REQUEST_URI} (\.\w+$) [NC]
    RewriteRule ^(.*)$ public/$1 
    
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ server.php
    
    

    You can get more reference here.

提交回复
热议问题