apache - 对于使用 modperl 的站点,使用 Apache RedirectPermanent 将 HTTP 重定向到 HTTPS
问题描述
modperl
我有一个 Apache 2.4 站点,它提供通过 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
?
解决方案
要重定向站点中的任何路径,您可能需要使用mod_rewrite
. 这些规则应该有效:
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R=301,L]
(我已经从这个问题中删除了perl
andmod_perl
标记。重写发生在服务器关心它将如何提供内容之前很久。)
推荐阅读
- angularjs - 如何在angularjs中使用alasql包装文本内容
- doxygen - 将 Doyxgen xml 输出转换为 DITA
- jquery - jQuery UI 调整大小,同时保持相同的整体宽度
- regex - 使用 RegEx 将大写转换为 title()
- actions-on-google - 我可以阻止参数被截断吗?
- javascript - 使用 Angularjs 在动态列表项中添加事件 stopPropagation
- android - 在 Realm 中实现回调并将其设置在 Presenter MVP 中以进行异步工作
- jquery - jQuery 序列化添加名为 '_' 的附加字段(下划线)
- php - 如何在 laravel 5.6 中使用 ajax 将数据从控制器传递到视图
- google-cloud-platform - 来自`datastore.NewQuery("").Ancestor(myKey)`的`datastore:invalid entity type`错误