I have a problem with .htaccess
I have a certificate in my server, and it's only for https://example.com (not https://www.example.com) Therefore, I'm trying to do a .htaccess redirect to the correct url.
My intention is this:
http://www.example.com --> https://example.com
http://example.com --> https://example.com
https://www.example.com --> https://example.com
I tried different combinations and nothing seems to work. At the moment I have this, but seems like is not working for
http://www.example.com/subfolder
, I don't know what is failing...
RewriteEngine On
# Follow symbolic links.
Options +FollowSymLinks
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
# Prevent directory listings
Options All -Indexes
Replace your current code by this one
Options -Indexes +FollowSymLinks
RewriteEngine On
# redirect "www" domain to https://example.com
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
# redirect http to https (at this point, domain is without "www")
RewriteCond %{HTTPS} =off
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
That code is not working for me, I found that, which works for me
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With