Webmasters Stack Exchange is a question and answer site for pro webmasters. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've got an ecommerce site where we're have some reports (random) of the cart not operating correctly. I think it might be due to removing www not working with https

my current htaccess code looks like this:

# remove the www
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.domain.com$ [NC]
RewriteRule ^(.*)$ http://domain.com/$1 [R=301,L]

What do I need to do to also force this on https?

share|improve this question
up vote 5 down vote accepted

This looks like the same situation covered here: http://stackoverflow.com/questions/3634101/url-rewriting-for-different-protocols-in-htaccess

Here is the code for removing the www from your hosts, regardless of http or https protocol

RewriteCond %{HTTP_HOST} ^www\.
RewriteCond %{HTTPS}s ^on(s)|off
RewriteCond http%1://%{HTTP_HOST} ^(https?://)(www\.)?(.+)$
RewriteRule ^ %1%3%{REQUEST_URI} [R=301,L]
share|improve this answer
How would you also force https? I'm trying to do both, but can't find anything that covers it. – Matthew Johnson Mar 11 '14 at 5:41
To force https, you could change the last rewrite rule to RewriteRule ^ https://%3%{REQUEST_URI} [R=301,L] You would also need another rule to redirect from http://example.com/ to https://example.com/ – Stephen Ostermiller Mar 11 '14 at 9:26

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.