I created a .htaccess file that does two things: redirects http to https and also www. to non-www. Here is the code:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.profstream.com [NC]
RewriteRule ^(.*)$ https://profstream.com/$1 [L,R=301]
This works fine in Chrome, Safari, and Opera but for some reason when I type profstream.com/sandbox/login.php for example in Firefox it redirects to https://profstream.com/https://www.profstream.com/sandbox/login.php. What am I doing wrong here?
I think you are missing [L] and also [QSA], try this:
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [QSA,L]
L
is to leave, otherwise you will use the rules after this.
QSA
is to add the query string of the URL.
The second part should be this I think:
RewriteCond %{HTTP_HOST} ^www.profstream.com [NC]
RewriteRule (.*) https://profstream.com%{REQUEST_URI} [QSA,L]
Don't know about the RewriteBase /
, is that needed?
And if you want both to happen, perhaps you should reverse the order
RewriteCond %{HTTP_HOST} ^www.profstream.com [NC]
RewriteRule (.*) https://profstream.com%{REQUEST_URI} [QSA,L]
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [QSA,L]