[英]redirect http and https non-www and www urls to secure www url in apache2 site.conf
I want all the following urls: 我想要以下所有网址:
-http://xyz.com.au
-http://www.xyz.com.au
-https://xyz.com.au
-https://www.xyz.com.au
to resolve to 解决
https://www.xyz.com.au
To accomplish this I have created /etc/apache2/sites-available/xyz.conf file as follows: 为此,我创建了/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>
This results in the following url redirects: 这将导致以下URL重定向:
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)
To try and correct the https://xyz.com.au redirect I added the following lines directly below the SSLCertificateKeyFile ... 为了尝试和更正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]
And now I get the following results: 现在,我得到以下结果:
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)
So I have effectively fixing the https://xyz.com.au redirect but now with the added //. 因此,我已经有效地修复了https://xyz.com.au重定向,但是现在添加了//。 Why is this happening? 为什么会这样呢?
NOTE: my cert is for www.xyz.com.au. 注意:我的证书适用于www.xyz.com.au。
I used the examples in this link for the :80 vhost permanent redirects. 我在此链接中将示例用于:80 vhost永久重定向。
https://wiki.apache.org/httpd/RedirectSSL
Both HTTP redirects take more than 1000ms, which seems way too long, especially considering that the https://xyz.com.au --> https://www.xyz.com.au// redirect takes only about 3ms. 这两个HTTP重定向都需要1000毫秒以上的时间,这似乎太长了,特别是考虑到https ://xyz.com.au-> https://www.xyz.com.au//重定向仅需要3毫秒。 Is this normal behaviour? 这是正常行为吗?
Am I doing this incorrectly, and if so what is the correct and most responsive way to perform the redirects? 我这样做有误吗?如果是,执行重定向的正确且响应速度最快的方法是什么?
So I have effectively fixing the https://xyz.com.au redirect but now with the added //. 因此,我已经有效地修复了https://xyz.com.au重定向,但是现在添加了//。 Why is this happening? 为什么会这样呢?
NOTE: my cert is for www.xyz.com.au. 注意:我的证书适用于www.xyz.com.au。
If your cert is for www.xyz.com.au you can't redirect https://xyz.com.au to https://www.xyz.com.au because the browser will refused the first redirect : https://xyz.com.au do not have a valid certificate 如果您的证书适用于www.xyz.com.au,则无法将https://xyz.com.au重定向到https://www.xyz.com.au,因为浏览器将拒绝首次重定向: https:/ /xyz.com.au没有有效的证书
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.