Jump to content

Recommended Posts

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

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

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

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.