Laravel 要求域的根目录(在相关的 apache vhost conf 文件中配置)是它的“公共”文件夹。这是它的入口点 index.php 所在的位置。
编辑 apache vhosts conf 文件,如下所示
<VirtualHost *:80>
ServerName example.com
DocumentRoot "/home/user/public_html/public"
<Directory "/home/user/public_html/public">
Options Indexes FollowSymLinks
AllowOverride all
Allow from all
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName staging.example.com
DocumentRoot "/home/user/public_html/staging/public"
<Directory "/home/user/public_html/staging/public">
Options Indexes FollowSymLinks
AllowOverride all
Allow from all
Require all granted
</Directory>
</VirtualHost>
例如.com,您将 laravel 应用程序安装到 /home/user/public_html 文件夹中。
作为 laravel 安装的一部分,它将创建“公共”文件夹。
对于staging.example.com,您将 laravel 应用程序安装到 /home/user/public_html/staging 文件夹中。
不要忘记重新启动 Web 服务器,以便它获取新配置。
如果您无法更改上述虚拟主机配置,则可以使用 public_html 文件夹中的 .htaccess 文件(注意前导句号使其成为隐藏文件)。以下内容取决于您的托管服务提供商是否允许 .htaccess 覆盖。
将以下内容添加到 .htaccess 文件中:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
如果在输入http://example.com时主机已正确设置域指向 /home/username/public_html,那么它应该自动调用 public/index.php。
您需要在 public_html/staging 文件夹中执行相同的操作。