Setting up a new add-on domain* for a client today and found that I could not access the new add-on domain name directly. It was appending the new add-on domain name to the root or main site url. So instead of taking the visitor to www.newdomain.com it was taking them to www.maindomain.com/newdomain.com, and of course I didn’t want the visitor to see that horrible URL, but only to see the new add-on domain name.

What was happening is there was an HTTPS redirect for all pages on the main site in the .htaccess file. The .htaccess rule was saying, “ANY page visited on the site, redirect to a hard-coded URL of HTTPS, for that page.”

This is what the rule looked like initially:

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://domain.com/$1 [R,L]</pre>
I needed an .htaccess rule that forced HTTPS on the main site, but left the add-on domain alone to do it's own thing. Here's the rule that solved the issue:
<pre class="lang:default decode:true" title="Force main domain to HTTPS but leave add-on domains alone">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]

For the new .htaccess code replace yourdomain.com on line 7 with your domain. On lines 5 and 6, replace yourdomain\.com while remembering to insert the backslash before the period in your domain name.

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

 


* An addon domain is a fully functional domain that can be created from within your control panel. Think of it as having multiple hosting packages all sharing the same control panel. You can create email addresses, forwarders and more — the same way you do for your primary domain on the account.