【问题标题】:How does laravel redirect first to public folder?laravel 如何首先重定向到公用文件夹?
【发布时间】:2019-10-16 11:39:15
【问题描述】:

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

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

【问题讨论】:

  • 它没有重定向到公用文件夹。 文档根目录被设置到public文件夹。
  • 你使用的是 Apache 还是 Nginx?
  • 我正在使用 nginx 并在 valet 上运行,它自己做事,不关心任何 htaccess,所以我想这就是答案。

标签: laravel .htaccess


【解决方案1】:

laravel 5.8 我使用以下

root .htaccess

RewriteEngine On

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

公共/.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>

【讨论】:

    猜你喜欢
    • 2015-07-01
    • 1970-01-01
    • 2015-08-24
    • 1970-01-01
    • 2018-09-13
    • 1970-01-01
    • 2013-09-11
    • 1970-01-01
    • 2018-07-22
    相关资源
    最近更新 更多