Jay
Jay

Reputation: 312

Force HTTPS causing 404 redirect

I'm using .htaccess to force redirection to https://www.domain.com using the following code:

RewriteEngine On
RewriteCond %{HTTPS} !off
# First rewrite to HTTPS:
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Now, rewrite any request to the wrong domain to use www.
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

The above result in a page with encrypted output: enter image description here Is this a problem on my htaccess or, a server problem?

Upvotes: 1

Views: 560

Answers (2)

user5954718
user5954718

Reputation:

A server problem would be noted with a 5xx error. Check your logs and try this:

RewriteCond %{HTTPS} !on [OR]  
RewriteCond "%{HTTP_HOST}" "!^www\." [NC]  
RewriteCond "%{HTTP_HOST}" "!^$"
RewriteRule "^/?(.*)" "https://www.%{HTTP_HOST}/$1" [L,R,NE]

Upvotes: 0

Trevor
Trevor

Reputation: 26

CloudFlare doesn't use 443 port so, try this:

RewriteCond %{SERVER_PORT} 80 

Upvotes: 1

Related Questions