问题
The Details
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.
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.
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.
Can anyone help me do the following?
(please note: I had to add space between http(s):// and www below to break links in order to post my question)
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
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
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.
Thank you
回答1:
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]
来源:https://stackoverflow.com/questions/27882723/redirect-primary-domain-to-https-but-all-sub-domains-to-http-with-mod-rewrite-an