I have added .htaccess https redirect from www to non-www with:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.
RewriteCond %{HTTPS}s ^on(s)|off
RewriteCond http%1://%{HTTP_HOST} ^(https?://)(www.)?(.+)$
RewriteRule ^ %1%3%{REQUEST_URI} [R=301,L]
</IfModule>`
When I visit my domain, the following redirects happen without any problem:
http://www.example.com → http://example.com http://www.example.com/abc → http://example.com/abc
But when I visit my domain as https://www.example.com or https://www.example.com/abs, my domain does not redirect and shows the error code: SSL_ERROR_INTERNAL_ERROR_ALERT (in Firefox) or ERR_SSL_PROTOCOL_ERROR (in Chrome)
I have used WordPress and the plugin Really Simple SSL.
Any idea on how to fix my error?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
Before I give you the CODE, let me explain a few points:
Point 1:
It’s better if you only allow https links. Mixing http & https for the same content breaks the security added by https. With http, you can never be sure that your visitors are shown the same page you are providing from your server.
Point 2:
Search engines consider http & https sites to be different sites, even when the domain is the same. So if not set up properly, you may get duplicate penalty. So it’s recommended to go https all the way for better SEO as well.
Point 3:
Even with proper .htaccess CODE, you may get the same error if SSL is not set up properly. So after you change the .htaccess CODE, it’s better to test your SSL setup against standards. You may use tool such as this.
Recommended CODE:
Based on the points above, following is the CODE you may use:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} =off [OR]
RewriteCond %{HTTP_HOST} !^example.com$
RewriteRule ^(.*)$ "https://example.com/$1" [R=301,L]
# remaining htaccess mod_rewrite CODE for WordPress
</IfModule>
This will do the following example redirects:
http://www.example.com/ → https://example.com/ http://www.example.com/abc → https://example.com/abc https://www.example.com/ → https://example.com/ https://www.example.com/abc → https://example.com/abc # Additionally, even if your site is reachable by IP or # some other domains or subdomains, this CODE will fix that too http://Your_Server_IP/abc → https://example.com/abc http://sub-dmoani.example.com/abc → https://example.com/abc http://www.other-domain.com/abc → https://example.com/abc
Not Recommended CODE:
If for some reason, you don’t want to follow the above recommendation & still want to allow both http and https, you may use the following CODE (based on this answer):
<IfModule mod_rewrite.c>
RewriteEngine On
# set protocol variable
RewriteCond %{HTTPS} =on
RewriteRule ^(.*)$ - [env=proto:https]
RewriteCond %{HTTPS} =off
RewriteRule ^(.*)$ - [env=proto:http]
RewriteCond %{HTTP_HOST} !^example.com$
RewriteRule ^(.*)$ "%{ENV:proto}://example.com/$1" [R=301,L]
# remaining htaccess mod_rewrite CODE for WordPress
</IfModule>
This will do the following example redirects:
http://www.example.com/ → http://example.com/ http://www.example.com/abc → http://example.com/abc https://www.example.com/ → https://example.com/ https://www.example.com/abc → https://example.com/abc
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0