I'm having a bit of an issue with my .htaccess file. I recently got an SSL certificate for my website and the https:// is working perfectly. However, I wanted to redirect any traffic using http:// to the new https://, but there seems to be an conflict with a previous rule I have.

Here's my .htaccess file:

# 404 Document Location
ErrorDocument 404 /404.html
# Turning Redirects On
RewriteEngine On
# Redirection from HTTP to HTTPS
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
# Redirection for filenames ending in .html
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]

Basically, the first redirection is supposed to be moving people from http:// to https://, the second is the one I previously had to truncate filetypes from the end of a domain (e.g. /cv.html is just /cv).

Can anyone see the conflict and let me know how to sort it?



Try this

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

I think you might have to call that rule the last one, and then do the suffixing on the next visit when https is there.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.