Redirect HTTP to HTTPS and WWW to NON-WWW URL

2019-07-22 06:02发布

I'm trying to redirect all HTTP requests to HTTPS and all www to non-www URLs.

That is,

  1. http://example.net to https://example.net
  2. http://www.example.net to https://example.net
  3. http://www.example.net to https://example.net
  4. https://www.example.net to https://example.net

I was successfully able to redirect URL conditions (1, 2 & 3) but the 4th redirect condition does not work, i.e. https://www.example.net to https://example.net.

I have an SSL certificate for both www and non-www URLs for my website. I'm currently using WordPress.

My .htaccess file contains the following code:

RewriteEngine On 
RewriteCond %{HTTPS} off 
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.*)$ [NC]
RewriteRule (.*) https://%1%{REQUEST_URI} [L,R=301]

I've tried many different redirect conditions but none worked.

I get the following error in Firefox:

An error occurred during a connection to www.example.net. Peer reports it experienced an internal error. Error code: SSL_ERROR_INTERNAL_ERROR_ALERT

What can I do to redirect the 4th URL condition?

1条回答
家丑人穷心不美
2楼-- · 2019-07-22 06:07

I finally found the solution to the problem. It is CloudFare, I was using the free version.

Turning off cloudfare for my website from Cpanel made all the redirects work.

查看更多
登录 后发表回答