Forcing "www." and "https" not working


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 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?


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=“”>
Redirect /

<virtualhost *:443=“”>
… 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 ^(.*)$$1 [R=301,L]

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