-1

I am using the following in my .htaccess file to force https on any user that is visiting my website without https in the url.

However, if the user visits https://www.mysite.co, I want to be able to remove the www from the request.

Please can you tell me what I need to modify in my .htaccess file in order to remove the www from the url while maintaining the forceful https?

Thanks,

Max.

RewriteEngine On 
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://mysite.co/$1 [R,L]
max_
  • 24,076
  • 39
  • 122
  • 211
  • Duplicate: http://stackoverflow.com/questions/6399406/remove-www-from-https – Aamir Nov 09 '12 at 23:54
  • See this post... It's a good explaination http://stackoverflow.com/questions/10725357/redirect-https-to-non-www-and-http-to-www/10726167#10726167 – Zak Nov 09 '12 at 23:56
  • ...if its a duplicate of stuff you already have please close it *as a duplicate* -- Server Fault already has a million mo.d_rewrite questions and your duplicate target would have been better than [ours](http://serverfault.com/questions/214512/everything-you-ever-wanted-to-know-about-mod-rewrite-rules-but-were-afraid-to-as) – voretaq7 Nov 10 '12 at 19:17

1 Answers1

2

Do it with 2 rewrites.

RewriteEngine On 

RewriteCond %{HTTPS}  off
RewriteRule ^(.*)$ https://mysite.co/$1 [R,L]

RewriteCond %{HTTPS}  on
RewriteCond %{HTTP_HOST}  ^www\. [NC]
RewriteRule ^(.*)$ https://mysite.co/$1 [R,L]
CoffeeMonster
  • 2,160
  • 4
  • 20
  • 34