pioneerx01 Posted December 22, 2013 Share Posted December 22, 2013 I have a web hosting package what has multiple damins under it, hence there is only .htaccess for all domains in the root directory. Only one of my domains has SSL on it. What I need to do, is force SSL on that domain when users use non SSL link or domain and I need to have www. in the fornt if it is not listed. For example: if the come from mydomain.com they need to go to https://www.mydomain.com if the come from www.mydomain.com they need to go to https://www.mydomain.com if the come from mydomain.com/events they need to go to https://www.mydomain.com/events if the come from www.mydomain.com/events/register.php they need to go to https://www.mydomain.com/events/register.php I have looked on google, but none seem to take into account that I have other domains besides mydomain.com that are not SSL. I need only mydomain.com traffic redirected to SSL not all the domains. Any help would be appreciated Thanks Quote Link to comment Share on other sites More sharing options...
requinix Posted December 22, 2013 Share Posted December 22, 2013 There is but one line (perhaps multiple times) you'll need to add to whatever you found. Speaking of, what have you tried? And I assume the problem was that they redirected requests for all domains instead of just the one? Quote Link to comment Share on other sites More sharing options...
pioneerx01 Posted December 22, 2013 Author Share Posted December 22, 2013 (edited) Most are on the lines of RewriteEngine OnRewriteCond %{SERVER_PORT} 80RewriteRule ^(.*)$ https://www.example.com/$1 [R,L] or RewriteEngine OnRewriteCond %{HTTPS} offRewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} However they all default to the domain listed in the code or domain they requested originally. Yes, I am probably missing just one line that specifies "run only on this URL", but I have never worked with .htaccess code, so I have no idea how to code it porperply. Something like this, but there needs to be OR between the first two conditions. Maybe I should write each independenly? RewriteEngine On RewriteCond %{HTTP_HOST} domain.com RewriteCond %{HTTP_HOST} www.domain.com RewriteCond %{HTTPS} != on RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} Edited December 22, 2013 by pioneerx01 Quote Link to comment Share on other sites More sharing options...
kicken Posted December 22, 2013 Share Posted December 22, 2013 The second argument for RewriteCond is a regular expression, so you just make the www. part optional with a ? quantifier. RewriteCond %{HTTP_HOST} (www.)?domain.com There is a way to join the conditions as an OR however, by specifying the [OR] flag after the condition. With that you can take care of both your ssl requirement and you hostname requirement. RewriteCond %{HTTP_HOST} (www.)?example.com RewriteCond %{HTTPS} =off [OR] RewriteCond %{HTTP_HOST} !www.example.com RewriteRule (.*) https://www.example.com$1 [R=301,QSA,L] Quote Link to comment Share on other sites More sharing options...
pioneerx01 Posted December 22, 2013 Author Share Posted December 22, 2013 Again this could be my lack on .htaccess coding knowledge, but should't the code be: RewriteCond %{HTTPS} =off RewriteCond %{HTTP_HOST} (www.)?example.com [OR] RewriteCond %{HTTP_HOST} !www.example.com RewriteRule (.*) https://www.example.com$1 [R=301,QSA,L] Because the one listed by kicken in above post in my mind reads: If (HTTP_HOST == “www.example.com” and (HTTPS == “off” OR HTTP_HOST != “www.example.com”)) rewriterule… So if I come from "example.com" I will not get redirected to SSL I will try the code anyways once it gets later in the evening/early morning. I want to minimaze the number of pottential users during the day that might be effected. Thanks Quote Link to comment Share on other sites More sharing options...
kicken Posted December 23, 2013 Share Posted December 23, 2013 Mine would read as: if (HTTP_HOST matches /(www.)?example.com/ AND (HTTPS=off OR HTTP_HOST does not match /www.example.com/)) redirect The first line limits the rules to only requests for www.example.com or example.com.The second line tests if SSL is not enabled The third line tests if the host is something other than www.example.com (which due to the first condition, could only be example.com) Because the second and third lines are joined with an [OR] tag, if either of them is true (ssl is not enabled OR the host is not www.example.com) it will redirect to www.example.com Quote Link to comment 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.