【问题标题】:Apache: Permanent Redirect to HTTPS with WildcardApache:使用通配符永久重定向到 HTTPS
【发布时间】:2018-01-31 12:51:04
【问题描述】:

我正在尝试将 HTTP 流量重定向到我服务器上的 HTTPS。

我有 this.example.net、that.example.net 和 etc.example.net 的证书,并且我的 DNS 接受通配符。我想使用通配符将 HTTP 永久重定向到 HTTPS。

我试过了:

<VirtualHost *:80>
    ServerName example.net:80
    ServerAlias *.example.net
    ServerAdmin mark@example.net
    RedirectMatch 301 (.*) https://$1.example.net
</VirtualHost>

但这不起作用。

我知道我可以通过这种方式设置单独的子域,但是可以使用通配符吗?

【问题讨论】:

标签: apache redirect wildcard virtualhost


【解决方案1】:

正如 Apache 2.4 httpd 的 RedirectMatch Directive 所说:

语法:RedirectMatch [status] 正则表达式 URL

该指令等效于 Redirect,但使用正则表达式,而不是简单的前缀匹配。

例子:

RedirectMatch "(.*)\.gif$" "http://other.example.com$1.jpg"

Apache 使用PCRE 兼容的正则表达式。

但通常应该足够使用:

Redirect permanent / https://www.example.com/

最后但并非最不重要的部分:Redirect 仅匹配 URL-path 而不是完整的 URL!

所以你最好为你正在使用的每个子域添加一个VirtualHost 配置。

【讨论】:

    猜你喜欢
    • 2016-09-06
    • 2013-05-20
    • 1970-01-01
    • 2021-11-10
    • 2011-07-30
    • 2021-10-09
    • 1970-01-01
    • 2020-04-22
    • 1970-01-01
    相关资源
    最近更新 更多