Jumpy09 Posted June 22, 2010 Share Posted June 22, 2010 So far I have: Options +FollowSymlinks RewriteEngine On RewriteCond %{HTTPS} off RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} RewriteCond %{http_host} ^example.net [nc] RewriteRule ^(.*)$ https://www.example.net/$1 [r=301,nc] This works fine for my standard domain, which obviously isn't example. But when I throw in sub-domains, which my SSL Cert doesn't cover, I have to force my users to make an exception. I need it to only switch the www.example.net over to https:// and switch http://example.net over to https://www but leave all the sub-domains as http:// Is this possible, or am I being too difficult? Link to comment https://forums.phpfreaks.com/topic/205508-ssl-rewrite/ Share on other sites More sharing options...
cags Posted June 22, 2010 Share Posted June 22, 2010 I think you probably want something like this... Options +FollowSymlinks RewriteEngine On RewriteCond %{HTTPS} off RewriteCond %{HTTP_HOST} ^www.example.net RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=302,NC,QSA] RewriteCond %{HTTPS} off RewriteCond %{HTTP_HOST} ^example.net [nc] RewriteRule ^(.*)$ https://www.example.net/$1 [R=302,NC,QSA] Note I have put them both as R=302, the main reason behind this is because if you use R=301 and get the rule wrong, it's a pain in the backside to get your browser to notice any changes to the .htaccess (since it doesn't request it because it knows it should be permanently re-directed), once you are happy your rules are working you can change it to 301. Link to comment https://forums.phpfreaks.com/topic/205508-ssl-rewrite/#findComment-1075463 Share on other sites More sharing options...
Jumpy09 Posted June 22, 2010 Author Share Posted June 22, 2010 Sweet, that's exactly what I needed. I also threw: RewriteCond %{HTTPS} on RewriteCond %{HTTP_HOST} ^example.net [nc] RewriteRule ^(.*)$ https://www.example.net/$1 [R=302,NC,QSA] In for good measure! Thanks a ton! BTW: What's the QSA for? Link to comment https://forums.phpfreaks.com/topic/205508-ssl-rewrite/#findComment-1075476 Share on other sites More sharing options...
cags Posted June 22, 2010 Share Posted June 22, 2010 Query String Attach/Append, you don't need it in this case, I tend to throw it into code I'm posting by default to avoid problems with people doing rewrites that involve query strings, as that's what most question involve. Example: # requested URL: http://example.com/article/1?lang=fr RewriteRule ^([^/]+)/([0-9]+)/?$ /index.php?page=$1&id=$2 # page displayed: http://example.com/?page=article&id=1 RewriteRule ^([^/]+)/([0-9]+)/?$ /index.php?page=$1&id=$2 [QSA] # page displayed: http://example.com/?lang=fr&page=article&id=1 Link to comment https://forums.phpfreaks.com/topic/205508-ssl-rewrite/#findComment-1075478 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.