Web & Software Developer

Redirect To HTTPS, But Only Apply it to One Domain on GoDaddy

Redirect your Godaddy domain from HTTP to HTTPS, but only apply it to one domain. Or, the second example shows you how to redirect all your GoDaddy domains except one domain. These are necessary if you are hosting multiple “Add-on” domains in your Linux/cPanel hosting account. If you use Godaddy’s rules for “Redirect HTTP to HTTPS automatically,” you will notice that all of your other domains which are hosted in the same hosting account will also redirect to the the main domain.

Example 1: Redirect Only 1 Domain, Not Any Add-on Domains

The following rules for your “.htaccess” file will fix this. Replace yourdomain.com on line 6 with your domain that you do want to redirect to HTTPS. On lines 4 and 5, replace yourdomain\.com while remembering to insert the backslash before the period in your domain name. All other domains, except for this one, will not be redirected.

RewriteEngine On
# Redirect to https, but only apply to one domain, not to add on domains
RewriteCond %{SERVER_PORT} !=443
RewriteCond %{HTTP_HOST} ^yourdomain\.com.* [OR]
RewriteCond %{HTTP_HOST} ^www\.yourdomain\.com.*
RewriteRule ^ https://yourdomain.com%{REQUEST_URI} [R=301,L]

Important: If you have existing code in your “.htaccess,” add this above where there are already rules with a similar starting prefix.

This works with WordPress, as well. Place these rules above the WordPress rules in your “.htaccess.”

Example 2: Redirect All Domains Except 1 Add-on Domain

The following rules for your “.htaccess” file will redirect all the domains in your cPanel hosting account, except for 1 domain. On lines 4 and 5, replace yourdomain\.com with your domain that you do not want to redirect, while remembering to insert the backslash before the period in your domain name. This domain will not be redirected to HTTPS. All other domains, except for this one, will be redirected from HTTP to HTTPS.

RewriteEngine On
# Redirect to https, but except for one domain...
RewriteCond %{SERVER_PORT} 80
RewriteCond %{HTTP_HOST} !^yourdomain\.com.*
RewriteCond %{HTTP_HOST} !^www\.yourdomain\.com.*
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Important: If you have existing code in your “.htaccess,” add this above where there are already rules with a similar starting prefix.

This works with WordPress, as well. Place these rules above the WordPress rules in your “.htaccess.”

By

We've 2 Responses

  1. June 22nd, 2015 at 9:06 pm

    Sorry, you can delete the previous comment, I had some other code that was messing with it, now it all works.

    Thanks so much, tried a whole bunch of stuff until I found this, thanks.

    avatar
  2. May 26th, 2017 at 1:16 pm

    You rock – I searched everywhere to get this answer and this was the first thing I could get to work. Thanks so much for sharing!

    avatar

Questions and Comments are Welcome

Your email address will not be published. All comments will be moderated.

Please wrap code in "code" bracket tags like this:

[code]

YOUR CODE HERE 

[/code]