使用mod_rewrite的Apache SSL重定向 [英] Apache ssl redirect using mod_rewrite
问题描述
我要做到这一点:如果他们这样做 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屋!