Forum Moderators: phranque

Message Too Old, No Replies

Cannot get force www AND preserve http/https to work

force www AND preserve http/https

         

uberschweiz

1:54 am on Aug 16, 2010 (gmt 0)

10+ Year Member



I've spent several hours trying to get this to work without luck. Here's my .htaccess

Options +FollowSymLinks -MultiViews

RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^brewtoppers\.com [NC]
RewriteCond %{HTTPS} =on
RewriteRule .* https://www.%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTP_HOST} ^brewtoppers\.com [NC]
RewriteCond %{HTTPS} !=on
RewriteRule .* http://www.%{SERVER_NAME}%{REQUEST_URI} [R=301,L]


Please test it out for yourself and see the resulting redirect behavior.

@jdMorgan I've tried some of your other options with no luck. Any help would be greatly appreciated.

Thanks,
Ben

g1smd

7:33 am on Aug 16, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



What EXACTLY is the code meant to do?

Please describe in terms of both http and https requests for both www and non-www.

uberschweiz

7:40 am on Aug 16, 2010 (gmt 0)

10+ Year Member



Intended to redirect:

[brewtoppers.com...] TO [brewtoppers.com...]

AND

[brewtoppers.com...] TO [brewtoppers.com...]

The main idea is to force www for both http and https. I've been able to get 3 of 4 to work. The elusive one has been redirecting [brewtoppers.com...] TO [brewtoppers.com...]

Thanks,
Ben

jdMorgan

2:16 am on Aug 19, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm not sure which of "my other options" you've tried, but if none of them work, then that would imply that the code is not being executed for https requests.

That most would likely be because because you're testing the non-server-native variable %{HTTPS} for a value of "on" instead of testing %{SERVER_PORT} for a value of 443, or because your https requests resolve to a different filespace on your server, and this .htaccess file is consequently not executed for those requests.

It is also unclear why you've used "%{SERVER_NAME}" in your substitution. It would be simpler (and safer) to simply specify "brewtoppers.com" instead.

Jim