将HTTP重定向到HTTPS并将WWW重定向到NON-WWW URL [英] Redirect HTTP to HTTPS and WWW to NON-WWW URL

查看:125
本文介绍了将HTTP重定向到HTTPS并将WWW重定向到NON-WWW URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将所有HTTP请求重定向到HTTPS,并将所有www重定向到非www URL.

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

也就是说,

  1. http://example.net http://www.example.net http://www.example.net https://www.example.net
  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

我成功地能够重定向URL条件(1、2和3),但是第4个重定向条件不起作用,即 https://www.example.net 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.

我为我的网站的www和非www URL都具有SSL证书.我当前正在使用WordPress.

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

我的.htaccess文件包含以下代码:

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.

我在Firefox中收到以下错误:

I get the following error in Firefox:

在连接到www.example.net时发生错误.对等方报告它遇到内部错误.错误代码:SSL_ERROR_INTERNAL_ERROR_ALERT

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

我该怎么做才能重定向第四个URL条件?

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

推荐答案

我终于找到了解决问题的方法.是CloudFare,我使用的是免费版本.

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

通过Cpanel为我的网站关闭cloudfare可使所有重定向正常工作.

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

这篇关于将HTTP重定向到HTTPS并将WWW重定向到NON-WWW URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆