I'd like to redirect all subdomains (i've wildcard subdomains set up in apache virtualhost) to https, if http, for all except www.domain.com
Any ideas greatfully appreciated.
开发者_开发问答Here's what I have so far:
# Redirect subdomains to https
#RewriteCond %{HTTPS} off
#RewriteCond %{HTTP_HOST} ^(*)\. [NC]
#RewriteCond %{HTTP_HOST} !^(www)\. [NC]
#RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
Thanks!
Try this code in your .htaccess file:
Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteCond %{SERVER_PORT} =80
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
This should help you:
RewriteCond %{HTTP_HOST} !^(www\.)localhost.com$
RewriteCond %{HTTP_HOST} ^(.*?)\.localhost.com$
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*?)$ https://%{HTTP_HOST} [nc]
First RewriteCond
: If the website doesn't start with www
Second RewriteCond
: Get any subdomain
Third RewriteCond
: Check that https isn't already within the requested url
RewriteRule
: Redirect to https version of site
精彩评论