我试图在反向代理后面的Laravel应用程序中通过Apache Vhost重定向强制FQDN和HTTPS。我现在的问题是用户有时会重定向到带有双斜杠的网址,例如https://exampledomain.xy//test
而不是https://exampledomain.xy/test
,但我不确定为什么。
这是我的apache虚拟主机配置:
<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}]
答案 0 :(得分:0)
好的,看来我已经解决了这个问题。我在配置中更改了以下内容:
RewriteCond %{HTTPS} !on
RewriteRule ^(.*)$ https://stk-support.ukl.uni-freiburg.de$1 [R=301,L]
重写规则中的多余斜杠引起了问题,我还添加了HTTPS重写条件。