【发布时间】:2019-04-16 16:25:58
【问题描述】:
我试图在反向代理后面的 Laravel 应用程序中通过 Apache Vhost 重定向强制 FQDN 和 HTTPS。我现在的问题是用户有时会被重定向到带有双斜杠的 URL,例如https://exampledomain.xy//test 而不是 https://exampledomain.xy/test 我不知道为什么。
这是我的 apache vhost 配置:
<VirtualHost *:80>
ServerName localhost
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/public
<Directory /var/www/html>
AllowOverride All
</Directory>
ErrorLog /dev/stderr
TransferLog /dev/stdout
RewriteEngine on
RewriteCond %{HTTP_HOST} !=localhost
RewriteCond %{HTTP_HOST} !=127.0.0.1
RewriteCond %{REMOTE_ADDR} !=127.0.0.1
RewriteCond %{REMOTE_ADDR} !=::1
RewriteRule (.*) https://exampledomain.xy/$1 [L,R=301]
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot "/var/www/html/public"
ServerName exampledomain.xy
</VirtualHost>
还有我的 .htaccess 文件(Laravel 自带的默认 .htacces 文件)
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
【问题讨论】:
标签: apache redirect mod-rewrite https vhosts