【问题标题】:redirect http and https non-www and www urls to secure www url in apache2 site.conf重定向 http 和 https 非 www 和 www url 以保护 apache2 site.conf 中的 www url
【发布时间】:2016-05-20 18:46:40
【问题描述】:

我想要以下所有网址:

-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 --> https://www.xyz.com.au// 重定向只需要大约 3 毫秒。 这是正常行为吗?

我这样做是否不正确,如果是,那么执行重定向的正确且响应速度最快的方式是什么?

【问题讨论】:

    标签: http https debian apache2 url-redirection


    【解决方案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 没有有效证书

    【讨论】:

    • 可以通过使用通配符证书来解决这个问题吗?
    • 没有。 *.xyz.com 仅适用于 a.xyz.com、b.xyz.com、c.xyz.com、.. 而不适用于 xyz.com 本身但您可以拥有 xyz.com 和 www 的多域证书.xyz.com
    猜你喜欢
    • 2014-12-16
    • 2018-09-26
    • 2017-12-04
    • 1970-01-01
    • 1970-01-01
    • 2015-04-20
    • 2015-04-06
    • 2015-05-01
    • 2012-05-30
    相关资源
    最近更新 更多