NeoVidaMedia Posted December 8, 2014 Share Posted December 8, 2014 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 } Quote Link to comment https://forums.phpfreaks.com/topic/292973-ssl-certificate-addon-domains-and-modrewrite/ Share on other sites More sharing options...
NeoVidaMedia Posted December 8, 2014 Author Share Posted December 8, 2014 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/ Quote Link to comment https://forums.phpfreaks.com/topic/292973-ssl-certificate-addon-domains-and-modrewrite/#findComment-1499057 Share on other sites More sharing options...
kicken Posted December 9, 2014 Share Posted December 9, 2014 (edited) 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 December 9, 2014 by kicken Quote Link to comment https://forums.phpfreaks.com/topic/292973-ssl-certificate-addon-domains-and-modrewrite/#findComment-1499081 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.