【问题标题】:Redirecting HTTP to HTTPS with Apache RedirectPermanent for sites that use modperl对于使用 modperl 的站点,使用 Apache RedirectPermanent 将 HTTP 重定向到 HTTPS
【发布时间】:2020-03-07 07:26:31
【问题描述】:

我有一个 Apache 2.4 站点,它提供由 modperl 通过 HTTPS 生成的内容。相关Location部分如下:

<Location />
  SetHandler modperl
  PerlResponseHandler MyService
</Location>

我现在也想通过 HTTP 启用相同的内容。下面的/etc/apache2/sites-enabled/myservice.conf 在某种程度上起作用,因为它重定向带有尾随路径的 URL,而不是“根”页面(例如,http://myservice.mycompany.com)。我怀疑这是(也)因为此页面的特殊之处在于它由modperl 支持。

<VirtualHost *:80>
  LogLevel debug
  ServerName myservice.mycompany.com
  RedirectPermanent / https://myservice.mycompany.com
</VirtualHost>

那么我如何使用RedirectPermanent 将整个Apache 站点从HTTP 重定向到HTTPS,包括那些由modperl 支持的页面?

【问题讨论】:

    标签: apache redirect https


    【解决方案1】:

    要重定向站点中的任何路径,您可能需要使用mod_rewrite。这些规则应该有效:

    RewriteEngine On
    RewriteCond %{HTTPS} !=on
    RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R=301,L]
    

    (我已经从这个问题中删除了perlmod_perl 标签。重写发生在服务器关心它将如何提供内容之前很久。)

    【讨论】:

    • 很好,这似乎工作正常。我仍然不明白为什么使用RedirectPermanent 的另一种方法(即使用mod_alias 而不是mod_rewrite 的方法)也不起作用,但这只是现在的学术兴趣。
    • @rookie099:您的原始版本确实有效。但它只重定向单个路径/。我的版本重定向服务器上的所有路径。您可能可以使用RedirectMatch 而不是RedirectPermanent 来做某事。
    猜你喜欢
    • 1970-01-01
    • 2020-02-08
    • 2021-03-02
    • 2014-08-18
    • 2017-06-07
    • 2019-11-08
    • 2021-05-11
    • 2011-04-19
    • 2020-08-13
    相关资源
    最近更新 更多