Apache vhost-重定向上的双斜杠



我试图通过反向代理后面的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附带的默认.htaces文件(

<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}]

看起来我解决了这个问题。我在配置中更改了以下内容:

RewriteCond %{HTTPS} !on
RewriteRule ^(.*)$ https://stk-support.ukl.uni-freiburg.de$1 [R=301,L]

重写规则中的额外斜杠导致了这个问题,我还添加了HTTPS重写条件。

最新更新