如何将 Apache 设置为 运行 Laravel 根于子路径?
How to setup Apache to run Laravel rooted from a subpath?
example.com
的DocumentRoot
在/var/www/html
。
Laravel 安装在 /var/www/example/public
中,我可以使用 http://example.com/dashboard
访问它,但是当我尝试访问其他路由(如 http://example.com/dashboard/login
并抛出 404 Not Found
错误。并说 The requested URL /var/www/example/public/index.php was not found on this server.
谁能指导我?
public 目录中的 .htaccess 文件未被修改。
这里是 000-default.conf
:
ServerName example.com
UseCanonicalName Off
<Directory /var/www/html/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
Alias /dashboard /var/www/example/public
<Directory /var/www/example/public>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
#dynamic subdomain provisioning
<VirtualHost *:80>
DocumentRoot /var/www/example/public
ServerName user.example.com
ServerAlias *.example.com
<Directory /var/www/example/public>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
我可以在 000-default.conf
文件中使用以下内容来解决:
<Directory /var/www/example/public>
DirectoryIndex index.php
AcceptPathInfo on
AllowOverride All
Options None
Order allow,deny
Allow from all
</Directory>
并且必须按以下方式更改 laravel.htaccess:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteBase /dashboard
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ dashboard/ [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
example.com
的DocumentRoot
在/var/www/html
。
Laravel 安装在 /var/www/example/public
中,我可以使用 http://example.com/dashboard
访问它,但是当我尝试访问其他路由(如 http://example.com/dashboard/login
并抛出 404 Not Found
错误。并说 The requested URL /var/www/example/public/index.php was not found on this server.
谁能指导我?
public 目录中的 .htaccess 文件未被修改。
这里是 000-default.conf
:
ServerName example.com
UseCanonicalName Off
<Directory /var/www/html/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
Alias /dashboard /var/www/example/public
<Directory /var/www/example/public>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
#dynamic subdomain provisioning
<VirtualHost *:80>
DocumentRoot /var/www/example/public
ServerName user.example.com
ServerAlias *.example.com
<Directory /var/www/example/public>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
我可以在 000-default.conf
文件中使用以下内容来解决:
<Directory /var/www/example/public>
DirectoryIndex index.php
AcceptPathInfo on
AllowOverride All
Options None
Order allow,deny
Allow from all
</Directory>
并且必须按以下方式更改 laravel.htaccess:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteBase /dashboard
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ dashboard/ [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>