.htaccess HTTPS main domain and force HTTP on add-on domain - apache

I'm on a shared hosting plan having 1 main domain and 1 add-on domain.
I just installed SSL certificate, however, I encountred the following problem
HTTPS on main domain works fine, but when accessing the addon domain I'm getting redirected to another site with HTTPS. I'm able to access the addon domain without HTTP but would it be possible to force HTTPS to HTTP or remove access to HTTPS for the add-on domain?
This is what I currently have in .htaccess
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Without the add-on domain. Use (instead of your code):
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !addondomain\.com$ [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Force HTTPS to HTTP for the add-on domain. Add:
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} addondomain\.com$ [NC]
RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Related

Redirect only HTTP subdomain to HTTPS subdomain in htaccess

How do you redirect only the HTTP subdomain to HTTPS subdomain in .htaccess? The main site is in WordPress and already redirected to HTTPS with a plugin, but the subdomain is a PHP created site. I have looked and not seen a conclusive solution to this on here.
I copy and pasted this suggested code but it did nothing:
#Redirect Subdomain
RewriteEngine on
RewriteCond %{HTTP_HOST} ^subdomain\.example\.com$ [NC]
RewriteRule .? https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteEngine on
RewriteCond %{HTTP_HOST} ^subdomain\.example\.com$ [NC]
RewriteRule .? https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
This would create a redirect loop (if executed at all). In order to redirect from HTTP to HTTPS you need to first check you are not already on HTTPS (otherwise you will get a redirect loop).
These directives would need to go in the .htaccess in the document root of your subdomain. Or at the top of your root (WordPress) .htaccess file if the subdomain points to the document root of the main site. The important thing is that the redirect must go before the WordPress front-controller.
This also assumes your SSL cert is installed directly on your application server and not a proxy.
Try the following:
RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteCond %{HTTP_HOST} ^subdomain\.example\.com [NC]
RewriteRule .? https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
This checks that HTTPS does not contain "on" and the subdomain is being requested before redirecting to HTTPS on the same host.
Although if WP is simply redirecting the main domain, then you could do all this in .htaccess and simply remove the condition that checks against HTTP_HOST. Although if you have other subdomains that should not be redirected to HTTPS then alter the CondPattern to match just the subdomain or main domain (and www subdomain). For example:
RewriteCond %{HTTP_HOST} ^((subdomain|www)\.)?example\.com [NC]
Please try one of the followings:
you need to edit
Redirect "/" "https://yourwebsite.com/"
OR
you dont need to edit following
RewriteEngine on
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^/(.*) https://%{HTTP_HOST}/$1 [NC,R=301,L]

HTTPS Redirect Using Parallels and Htaccess

I am doing a redirect from all domains to a single domain and then forcing it to HTTPS. All works for domains not entered with https: but when someone enters in the full url like https://www. the browser gives a certificate error. Below is my htaccess.
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Why is this not working for https requests? I am also using Parallels could there be a setting in that I am missing?

https for single domain .htaccess

I have a multiple addon domains on my hosting account. I would like to redirect non-https to https for the main domain i.e
andamanexoticholidays.com
my .htaccess approach:
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
but this makes all adon domain to force use ssl by default.
my addon domain are:
radhakrishnaresorthavelock.com
and my sud domains are:
agents.andamanexoticholidays.com
and I want to force use
https://www.andamanexoticholidays.com
a https and www.
any help would be appreciated.
Use a RewriteCondition so that only the main domain can get redirected to https , try :
RewriteCond %{HTTP_HOST} ^(www\.)?andamanexoticholidays.com$
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://www.andamanexoticholidays.com %{REQUEST_URI} [L,R=301]

Force HTTPS Through HTACCESS With Subdomain Exception

I'm looking to force HTTPS on my entire site except for a subdomain which I am using for a forum. I have an SSL certificate installed on the root domain, but not this forum subdomain. (http://forum.domain.com)
Here is the code for forcing HTTPS:
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
However, this also forces HTTPS on subdomains, which effectively makes the forum inaccessible.
How can I create an exception rule for this subdomain?
To exclude subdomain, you can use a negitive RewriteCond
RewriteCond %{HTTP_HOST} !^sub\.domain\.com$
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Subdomains Display The Wrong Content Using HTTPS

I am using a wildcard SSL on my main domain and a few sub-domains (apps, dashboard, support, training). The problem I am facing is that when I try to access a sub-domain via HTTPS, it shows the index/main page of the root domain, but when the sub-domain is accessed via HTTP, it shows the correct page. I would like to know what information I would need to put in the .htaccess file to make the sub-domains:
Automatically use HTTPS.
Show the correct content on that sub-domain when using HTTPS.
The sub-domains don't currently have an .htaccess file, because I have no idea what should be put in there at this point.
Here is an example of the HTTP sub-domain: http://goo.gl/Mcg66l
Here is an example of the HTTPS sub-domain: http://goo.gl/Aw9yl6
Here is the main domain: http://goo.gl/TfLjuy
The main domain is doing exactly what I want it to do (www to non-www and automatic https redirection), but the sub-domains are not doing what I want them to do, as described above.
Here is the .htaccess file on the main domain:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.(.*)
RewriteRule ^.*$ https://%1/$1 [R=301,L]
Lastly, I am using cPanel under a reseller account serviced by HostGator.
Thanks for taking a look at this problem!
I had the same exact issue, also using a HostGator account. I found the answer on another question that you can find here.
They go about solving it by applying HTTPS for the main domain, forcing HTTP on a subdomain, and then as a bonus remove all WWW's
# for main domain
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule ^ https://domain.com%{REQUEST_URI} [R=301,L,NE]
# for sub domain
RewriteCond %{HTTP_HOST} ^(www\.)?subdomain\.domain\.com$ [NC]
RewriteCond %{HTTPS} on [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule ^ http://subdomain.domain.com%{REQUEST_URI} [R=301,L,NE]