What re write rule is required to stop https on sub domain - .htaccess

I have the following rewrite rule in my domains .htaccess to add https to my existing http domain. Example www.mydomain.com
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
The issue I am having is the https is also being applied to my sub domain.
Example demos.mydomain.com
What code is required in the .htaccess to prevent the https on my sub domain?
Any help much appreciated.
Thanks.

try this,
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^www
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]

Related

https for main domain and http for subdomain

So i need very simple codes for .htaccess
I want to redirect all traffic to https in main domain and redirect all traffic to http in subdomain without WWW.
Right now i am using this code to redirect all traffic to https
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
So main domain should be like this: https://website.com
and subdomain should be like this: http://sub.website.com
I found many answers but very complicated, so need simple solution.
EDITED
Solution given by anubhava works great. Thanks for your solution.
You can use:
RewriteEngine On
# maindomain -> https
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(?:www\.)?(website\.com)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [R,L]
# subdomain -> http
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^(?:www\.)?(sub\.website\.com)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R,L]

Changing Subdomain from HTTPS to HTTP

Currently my main GoDaddy account has an SSL certificate, so by default all of my sites below automatically try and start with https://
So I have this in my htaccess file for all of my sites below and it works fine.
# All urls have www. in them
RewriteEngine on
RewriteCond %{HTTP_HOST} ^mydomainname\.com
RewriteRule ^(.*)$ http://www.mydomainname.com/$1 [R=permanent,L]
However when i try and do a subdomain, ie
# Sub Domain Rewrite
RewriteEngine on
RewriteCond %{HTTP_HOST} ^subname\.mydomainname\.com
RewriteRule ^(.*)$ http://subname.mydomainname.com/$1 [R=permanent,L]
It doesn't seem to work, any ideas?
Ok so it seems you need to place this rule in accord/.htaccess:
RewriteEngine On
# Sub Domain Rewrite
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^subname\.mydomainname\.com$ [NC]
RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [R=301,NE,L]

Remove SSL integration from a specific folder using htaccess

I have an integrated SSL for my entire site and have placed htaccess code to redirect to https when anyone visits my domain URL. But I want to keep one folder out of this redirection to https. Please help me with this... Below is the htaccess code placed in my root to redirect all requests to https counterpart
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
Thanks
Just add a condition to exclude the folder:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !^/folder1
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
And if you wanted to redirect SSL requests to non-SSL for /folder1, then:
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} ^/folder1
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Add www to URL with and without SSL

I am coding a website that uses SSL for most of the website.
At the moment I'm using a htaccess rule to add www to the URL, see the rule below:
RewriteCond %{HTTP_HOST} ^bettingproperties.com$ [NC]
RewriteRule ^(.*)$ http://www.bettingproperties.com/$1 [L,R=301]
How can I make it so that it will detect https and do the same also.
Try this, which should switch SSL traffic to regular HTTP:
RewriteEngine on
RewriteCond %{SERVER_PORT} ^443$
RewriteRule ^(.*)$ http://www.bettingproperties.com/$1 [L,R=301]
I found out that I can do this just by using the following.
RewriteCond %{HTTP_HOST} ^bettingproperties.com$ [NC]
RewriteRule ^(.*)$ https://www.bettingproperties.com/$1 [L,R=301]
Thanks for the help.

htaccess ssl redirection

I am trying to do ssl redirection for few pages only e.g. viewcart, checkout and when I try to apply this rule it gives me server 500 error.
Below is the lines I am using in my htaccess
RewriteCond %{HTTPS} on [s=2]
RewriteRule ^viewcart$ https://%{HTTP_HOST}/viewcart [R,L]
RewriteRule ^checkout$ https://%{HTTP_HOST}/checkout [R,L]
Thanks for help in advance. hope to get it resolved soon.
Thanks
mr p
s is not a valid flag for the RewriteCond directive
RewriteCond %{HTTPS} on [s=2]
You can achieve the same with below
#if not already https
RewriteCond %{HTTPS} off
RewriteRule ^viewcart$ https://%{HTTP_HOST}/viewcart [R,L]
#if not already https
RewriteCond %{HTTPS} off
RewriteRule ^checkout$ https://%{HTTP_HOST}/checkout [R,L]

Resources