使用mod_rewrite和htaccess将主域重定向到https但将所有子域重定向到http
详细信息
我有一个商业主机gator帐户......不吹牛......附带免费的私有SSL和IP。我正在运行一个使用子域设置的wordpress MU安装,并通过他们提供的插件设置域映射。
I have a business host gator account..not bragging.. that comes with a free Private SSL and IP. I am running a wordpress MU install that uses the sub-domain setting and have domain mapping setup via a plugin they offer.
假设你对Worpress MU一无所知......基本上Wordpress MU允许您在单个Wordpress安装下创建多个自托管博客。我有一个通配符子域设置来捕获所有sub.domain.com请求和Wordpress MU做一些伏都教将其重定向到正确的目的地。
Assuming you know nothing about Worpress MU... basically the Wordpress MU allows you to create multiple self hosted blogs under a single Wordpress install. I have a wildcard sub-domain setup to catch all sub.domain.com requests and Wordpress MU does some voodoo to redirect it to the proper destination.
私有SSL是免费所以我现在不打算使用通配符SSL,但我知道这是一个选项。当我说,当我点击从主域上的https到子域的任何链接时,https会粘贴到URL。
The private SSL is FREE so I am not going to shell out for a wildcard SSL right now but I do know that is an option. With that said when I, when I click any link from the https on the primary domain to a sub-domain the https sticks to the URL.
任何人都可以帮我做以下事情吗?
(请注意:我必须在http(s)://和www之间添加空格以打破链接以发布我的问题)
(please note: I had to add space between http(s):// and www below to break links in order to post my question)
对于主要的博客网址我想要示例www.domain.com和domain.com重定向到安全https,结果为https:// www.domain.com
For the primary "blog" url I would like both example www.domain.com and domain.com to redirect to a secure https with the result being https:// www.domain.com
对于通配符子域名子博客网址我想举例说明sub.domain.com和https:// sub.domain.com将表单ssl重定向到http,结果为http:// sub.domain.com
For the "wildcard" sub-domain "sub-blog" url I would like example sub.domain.com and https:// sub.domain.com to redirect away form ssl to http with the result being http:// sub.domain.com
代码示例将不胜感激并且一个详细的(虚拟)教程,所以我可以理解发生了什么将是伟大的。我是mod_rewrite的新手,我的技能等级仅限于基本的301重定向。
Code example would be appreciated and a detailed (dummy) tutorial so I can understand what is going on would be great. I am new to mod_rewrite my skill level is limited to basic 301 redirect.
谢谢
你可以在你的root中使用它 .htaccess
:
You can use that in your root .htaccess
:
RewriteEngine on
# redirect to https www
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(?:www\.)(domain\.com)$ [NC]
RewriteRule ^ https://www.%1%{REQUEST_URI} [R=301,L]
# redirect to http subdomain
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^((?!www).+\.domain\.com)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]