设置 .htaccess 文件以重定向到 Laravel 的公共文件夹
在这篇文章中,我们将学习如何设置 .htaccess 文件以重定向到 Laravel 的 public 文件夹。
在 Laravel 中,网页的运行路径位于 `/public` 文件夹内。默认情况下,安装 Laravel 后,在浏览器中访问该 URL 会看到一个包含所有 Laravel 文件的目录列表。这里介绍一种使用 `.htaccess` 文件将用户请求重定向到 Laravel `/public` 文件夹的简便方法(通过 mod_rewrite)。
在根目录下创建 .htaccess 文件,并添加以下代码。
<IfModule mod_rewrite.c>
# That was ONLY to protect you from 500 errors
# if your server did not have mod_rewrite enabled
RewriteEngine On
# RewriteBase /
# NOT needed unless you're using mod_alias to redirect
RewriteCond %{REQUEST_URI} !/public
RewriteRule ^(.*)$ public/$1 [L]
# Direct all requests to /public folder
</IfModule>
希望对您有所帮助。
文章来源:https://dev.to/vumanhtrung/setup-an-htaccess-file-for-redirecting-to-laravel-s-public-folder-1e1j