【问题标题】:Apache vhost double slash on redirects重定向时的 Apache vhost 双斜杠
【发布时间】: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


    【解决方案1】:

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-02-17
      • 2019-08-01
      • 2016-03-24
      • 1970-01-01
      • 2014-11-03
      • 2021-06-16
      • 1970-01-01
      • 2015-03-19
      相关资源
      最近更新 更多