使用mod_rewrite的Apache SSL重定向 [英] Apache ssl redirect using mod_rewrite

查看:103
本文介绍了使用mod_rewrite的Apache SSL重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要做到这一点:如果他们这样做 https://example.com 我想将它们重​​定向到 https://开头WWW。 example.com (添加 WWW。)。我已经试过的东西苦苦无济于事。

I want to do this: if they do https://example.com I want to redirect them to https://www.example.com (add the www.). I have tried oodles of things to no avail.

Redirect https://example.com/<anything> to https://www.example.com/<anything>
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteCond %{SERVER_PORT} =443
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]

这code是在httpd.conf,但在.htaccess和ssl.conf中已经尽力了。

This code is in httpd.conf but has been tried in .htaccess and ssl.conf.

谁能帮助?

推荐答案

重定向指令不只是URL路径上工作。但它可能与mod_rewrite的。此规则将在任何配置文件工作:

The Redirect directive does only work on the URL path. But it’s possible with mod_rewrite. This rule will work in any configuration file:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.com$
RewriteCond %{SERVER_PORT} =443
RewriteRule ^ https://www.example.com%{REQUEST_URI} [L,R=301]

不要忘了强制性的 RewriteEngine叙述上像(渣油已经说过)(1278432#1278432)。

And don’t forget the obligatory RewriteEngine on like (Residuum already said)(1278432#1278432).

这篇关于使用mod_rewrite的Apache SSL重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆