我想要以下所有网址:
-http://xyz.com.au
-http://www.xyz.com.au
-https://xyz.com.au
-https://www.xyz.com.au
解析为
https://www.xyz.com.au
为实现这一目标,我创建了/etc/apache2/sites-available/xyz.conf文件,如下所示:
AddDefaultCharset UTF-8
<VirtualHost *:80>
ServerName www.xyz.com.au
ServerAlias xyz.com.au
Redirect permanent / https://www.xyz.com.au
</VirtualHost>
<VirtualHost *:443>
ServerName www.xyz.com.au
ServerAlias xyz.com.au
DocumentRoot /var/www/xyz.com.au/vas_public
DirectoryIndex index.html
# ... SSL configuration goes here
SSLEngine on
SSLCertificateFile /etc/ssl/xyz/xyz.crt
SSLCertificateKeyFile /etc/ssl/xyz/xyz.key
</VirtualHost>
这导致以下网址重定向:
http://www.xyz.com.au --> https://www.xyz.com.au (responses 301, 200)
http://xyz.com.au --> https://www.xyz.com.au (responses 301, 200)
https://www.xyz.com.au --> https://www.xyz.com.au (responses 200)
https://xyz.com.au --> https://xyz.com.au (responses 301, 200)
尝试更正https://xyz.com.au重定向 我在SSLCertificateKeyFile ...
的正下方添加了以下行RewriteEngine On
RewriteCond %{HTTP_HOST} !=www.vasports.com.au [NC]
RewriteRule ^(.*) https://www.vasports.com.au/$1 [NS,L,R=permanent]
现在我得到以下结果:
http://www.xyz.com.au --> https://www.xyz.com.au (responses 301, 200)
http://xyz.com.au --> https://www.xyz.com.au (responses 301, 200)
https://www.xyz.com.au --> https://www.xyz.com.au (responses 200)
https://xyz.com.au --> https://www.xyz.com.au// (responses 301, 200)
所以我有效地修复了https://xyz.com.au重定向,但现在增加了//。为什么会这样?
注意:我的证书适用于www.xyz.com.au。
我在此链接中使用了以下示例:80 vhost永久重定向。
https://wiki.apache.org/httpd/RedirectSSL
两次HTTP重定向都需要超过1000毫秒,这似乎太长了,特别是考虑到https://xyz.com.au - &gt; https://www.xyz.com.au//重定向只需要大约3毫秒。 这是正常行为吗?
我这样做是否错误,如果是这样,执行重定向的正确和最敏感的方式是什么?
答案 0 :(得分:1)
所以我有效地修复了https://xyz.com.au重定向,但现在增加了//。为什么会这样?
注意:我的证书适用于www.xyz.com.au。
如果您的证书适用于www.xyz.com.au,则无法将https://xyz.com.au重定向到https://www.xyz.com.au,因为浏览器会拒绝第一次重定向:https://xyz.com.au没有效果证书