themule Posted May 26, 2010 Share Posted May 26, 2010 Hi, a client of mine purchased and SSL for www.mysite.com (not a wild card SSL) So when a user goes to https://mysite.com, we get some sort non-secure/trusted error. I'm trying to use mod_rewrite to force the www when it doesn't exist but nothing seems to work. Here is an example of my rewrite code: RewriteCond %{SERVER_PORT} ^443$ RewriteCond %{SERVER_NAME} ^mysite.com$ RewriteRule (.*) http://www.%{SERVER_NAME}%{REQUEST_URI} [R=301,NC,L] Quote Link to comment https://forums.phpfreaks.com/topic/202978-forcing-www-for-https/ Share on other sites More sharing options...
premiso Posted May 26, 2010 Share Posted May 26, 2010 Try this for the rule / cond's: RewriteCond %{SERVER_PORT} ^443$ RewriteCond %{HTTP_HOST} ^mysite.com RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,NC,L] If that does not work try this for the rule (keep the same conditions as above): RewriteRule ^(.*)$ https://www.mysite.com/$1 [R=301,NC,L] Since you are doing the port checking for 443, you should probably make the http be https Quote Link to comment https://forums.phpfreaks.com/topic/202978-forcing-www-for-https/#findComment-1063660 Share on other sites More sharing options...
themule Posted May 26, 2010 Author Share Posted May 26, 2010 Thanks for the catch on the https I tried both of those solutions and neither worked. Quote Link to comment https://forums.phpfreaks.com/topic/202978-forcing-www-for-https/#findComment-1063666 Share on other sites More sharing options...
premiso Posted May 26, 2010 Share Posted May 26, 2010 Well, I never used the SERVER_PORT command before, so I cannot vouch for that at all. But reading some other forums, you may take a look at the ending parts of this forum: http://www.webmasterworld.com/apache/3970987.htm It talks about your vhosts file and how it needs to be setup properly for this to work right. Let us know if that worked and possibly the right steps you had to take. Quote Link to comment https://forums.phpfreaks.com/topic/202978-forcing-www-for-https/#findComment-1063668 Share on other sites More sharing options...
cags Posted May 26, 2010 Share Posted May 26, 2010 Are all the Conds actually being met? I.E. does the URL actually change in the address bar? Quote Link to comment https://forums.phpfreaks.com/topic/202978-forcing-www-for-https/#findComment-1063816 Share on other sites More sharing options...
themule Posted May 26, 2010 Author Share Posted May 26, 2010 As far as I know they're being met. When I go to http://mysite.com the HTTP_HOST is mysite.com and if I go to https://www.mysite.com the SERVER_PORT is 443 Quote Link to comment https://forums.phpfreaks.com/topic/202978-forcing-www-for-https/#findComment-1063850 Share on other sites More sharing options...
cags Posted May 26, 2010 Share Posted May 26, 2010 Hypothesising about whether the CONDs are being met is irrelevant and pointless, as I asked in my last post does the URL in the address bar change after you have entered your test URL? If it doesn't then either the CONDS or the RULE itself are not being matched. Quote Link to comment https://forums.phpfreaks.com/topic/202978-forcing-www-for-https/#findComment-1063863 Share on other sites More sharing options...
themule Posted May 27, 2010 Author Share Posted May 27, 2010 No, the URl doesn't change, but is it possible the secure connection is attempted before the .htaccess file is read? Quote Link to comment https://forums.phpfreaks.com/topic/202978-forcing-www-for-https/#findComment-1064303 Share on other sites More sharing options...
cags Posted May 27, 2010 Share Posted May 27, 2010 What your .htaccess file seems to be doing is checking if the request is being made on port 443 and has the domain name mysite.com without any subdomain. So are we saying that the overall objective is to redirect any SSL requests to the base domain to the www. subdomain? Quote Link to comment https://forums.phpfreaks.com/topic/202978-forcing-www-for-https/#findComment-1064306 Share on other sites More sharing options...
themule Posted May 27, 2010 Author Share Posted May 27, 2010 No, the problem is that the SSL cert is only for www.domain.com, and if someone removes (and has) the www., they get the error. So what I want for SSL requests, is to make sure the URL has the www. No subdomains are being used. Quote Link to comment https://forums.phpfreaks.com/topic/202978-forcing-www-for-https/#findComment-1064322 Share on other sites More sharing options...
cags Posted May 27, 2010 Share Posted May 27, 2010 Err... www. IS a subdomain. Quote Link to comment https://forums.phpfreaks.com/topic/202978-forcing-www-for-https/#findComment-1064333 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.