Link to home
Start Free TrialLog in
Avatar of Witheet
WitheetFlag for Netherlands

asked on

htacces rewrite to send all traffic to https://www.

Hello all,

I am using the following code in my htacces file to redirect visitors to the https://www. version of the pages on a site...
This works fine in all browsers except with Internet explorer. using this browser the site will not load anymore...

RewriteEngine on
RewriteBase 
AllowOverride all

# rewrite non-www to www to prevent duplicate content
RewriteCond %{HTTP_HOST} ^mydomain.com [NC]
RewriteRule ^(.*)$ http://www.mydomain.com$1 [R=302,L]

# HTTPS for al pages
#RewriteCond %{HTTP_HOST} (.+) [NC]
#RewriteCond %{HTTPS} Off [NC]
#RewriteRule (.*) https:%1/$1 [R=302,L]

Open in new window


I will change the 302 to 301 when it is working correctly....
Can anyone please tell me what I am doing wrong here and point me in the right direction?

IE starts acting up as soon as it gets to the https for all pages piece of the code...

Thank you very much in advance!!!

With kind regards

RV
ASKER CERTIFIED SOLUTION
Avatar of Steve Bink
Steve Bink
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
This is what I use on all my sites and it works great.

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} !^www.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</IfModule>
Avatar of Witheet

ASKER

Hi Andrew,

I will test this later today and get back with feedback... TYVM for your reply...

wkr

rv
Hi

one quick note of advice. I have had some issues trying to get my wordpress site to rewrite to https:// and tried every conceivable method that I could google. None worked, various errors or non display.

In the end I spoke to the hosting company who gave me a set of rewrite rules specific to their hosting configuration and it worked on all browser as designed.

May be worth checking with your hoster to see if they have a similar scenario before chasing your tail.

capt.
Avatar of Witheet

ASKER

Captain,

Thank you for your reply... I actually did the same thing, but the code they gave me is this one and causes the ie issue...

wkr

rv
Avatar of Witheet

ASKER

Andrew,

Thank you for the code..
This code however makes the entire site shut down in chrome right of the bat...

wkr

rv
Avatar of Witheet

ASKER

The first solution does the trick...

TYVM!!! Glad to finally have it working in all browsers...

WKR

RV