Forcing "www." and "https" not working

Hi,

I have the following rewrite rules for forcing www. and https in URLs:

RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

The above code works perfectly fine on one website, but it does not work on another website on another server. The URL is eventually redirected to https://www.example.com/ but it says “The page isn’t redirecting properly” and doesn’t display the page.

Any ideas why it doesn’t work on one server, while it works on another?

Thanks.

not so sure this is the best way to do this @ennaido, if you have an SSL certificate installed you may be better updating the virtual host template on your server if you have access to it, this is much more secure.

I think you need to turn on Apache also, RewriteEngine On

<virtualhost *:80=“”>
ServerName www.example.com
Redirect / https://www.example.com/

<virtualhost *:443=“”>
ServerName www.example.com
… SSL configuration goes here

Here is what I have in my .htacess although I remove the www… this rule is forcing a redirect of all traffic for port 80 and sending it to port 443
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://costasonline.com/$1 [R=301,L]

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.