Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

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
add comment

1 Answer 1

up vote 4 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 at 5:41
1  
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 at 9:26
add comment

Your Answer

 
discard

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.