Jump to content

Recommended Posts

I recently installed a SSL certificate for one of my domains, on a hosting account that includes several other domains.  To redirect visitors to the SSL version of the website (because the SSL certificate only works for the www. version of the site) I use the following code in my .htaccess file:

 

#First rewrite any request to the wrong domain to use the correct one (here www.)
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
#Now, rewrite to HTTPS:
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
 
 
This works fantastically for the domain in question, but unfortunately it also happens for all other domains, none of which have SSL certificates, giving all visitors an error at the moment.
 
I am not very familiar with .htaccess functions, abilities, and code.  I am looking for something like this:
 
if (domain name includes 'domain1.com')
   {
   if (domain name also includes '/forums/' or '/blog/')
      {do nothing}
   else
 
 
   }

I've tried so many things!  I am getting a massive headache.  Just in case someone tried to help, here is some specific information:

 

On my hosting account I have the following domains:

 

realbanknotes.com

mcatzone.com

digitalproteus.com

 

I also have the following subdomains:

 

blog.realbanknotes.com

micro.digitalproteus.com

 

Also, I have the following directory:

 

realbanknotes.com/forums/

 

Here is what I have been trying to do:

 

 

 

RewriteCond %{HTTP_HOST} ^(realbanknotes\.com)$ [NC]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
 
As I understand it, this rule should only work for the domain 'realbanknotes.com.'.  It should not work for digitalproteus.com or mcatzone.com, but it does.  Also, I would like to exclude the following from this rule:
 
all domains other than realbanknotes.com (in this case exclude digitalproteus.com and mcatzone.com)
subdomain:  blog.realbanknotes.com
directory:  realbanknotes.com/forums/
 
 
 
The second rule is this:
 
RewriteCond %{HTTP_HOST} ^(www\.realbanknotes\.com)$ [NC]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
 
As I understand it, this second rule should only work for the domain 'realbanknotes.com' as well.  It should not work for digitalproteus.com or mcatzone.com, but it does.  Also, I would like to exclude the following from this rule:
 
all domains other than realbanknotes.com (in this case exclude digitalproteus.com and mcatzone.com)
subdomain:  blog.realbanknotes.com
directory:  realbanknotes.com/forums/
 

RewriteCond %{HTTP_HOST} ^realbanknotes\.com$ [NC]
RewriteRule ^(.*)$ https://www.realbanknotes.com/%{REQUEST_URI} [L,R=301]

RewriteCond %{HTTP_HOST} ^(www\.)?realbanknotes\.com$ [NC]
RewriteCond %{HTTPS} =off
RewriteRule ^(.*)$ https://www.realbanknotes.com/%{REQUEST_URI} [L,R=301]
Untested, but I think something like that should work to redirect only the one domain but not it's blog subdomain.

 

If you want to try and exclude the /forums folder, you'd have to add another condition matching the request URI, however there's not really much reason to exclude specific folders from these conditions.

Edited by kicken
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.