laravel如何首先重定向到公用文件夹?

时间:2019-05-30 19:36:48

标签: laravel .htaccess

我正在查看一个laravel 5.8项目,我试图了解Laravel如何将所有请求从/重定向到/ public文件夹。

根目录中没有index.php文件,也没有.htaccess来将流量重定向到公共位置?

1 个答案:

答案 0 :(得分:2)

laravel 5.8我使用以下

根.htaccess

RewriteEngine On

RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(.*)$ /public/$1 [L,QSA]

public / .htaccess

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews -Indexes
    </IfModule>

    RewriteEngine On

    # Handle Authorization Header
    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]
</IfModule>