Laravel 5 – Remove Public from URL

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

    
        
            Options -MultiViews -Indexes
        
    
        RewriteEngine On
    
        # Handle Authorization Header
        RewriteRule ^(.*)$ public/$1 [L]
        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_FILENAME} !-d
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule ^ index.php [L]
    
    

    Activate the mod_rewrite module with

    sudo a2enmod rewrite
    

    and restart the apache

    sudo service apache2 restart
    

    To use mod_rewrite from within .htaccess files (which is a very common use case), edit the default VirtualHost with

    sudo nano /etc/apache2/sites-available/000-default.conf
    

    Below "DocumentRoot /var/www/html" add the following lines:

    
    AllowOverride All
    
    

    Restart the server again:

    sudo service apache2 restart
    

提交回复
热议问题