【发布时间】:2022-08-22 22:44:33
【问题描述】:
我有一个必须放在子目录中的 Laravel 应用程序。使用 Apache,我发现了一个有效的 VirtualHost 虚拟主机是:
<VirtualHost *:80>
ServerName bar.localhost
Alias /foo /home/me/foo/public
<Directory /home/me/foo/public>
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
当我转到 \"http://bar.localhost/foo\" 时,页面被加载,另一个 \"foo\" 被添加到 URL (http://bar.localhost/foo/foo),这给应用程序重定向返回带来了很多麻烦。
.env 文件中的 APP_URL 是 \"http://bar.localhost/foo\"
.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]
# Send Requests To Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>