本文介绍了如何强制HTTPS(CloudFlare的灵活SSL)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个网站,我自己的编程(没有框架或CMS)使用CloudFlare的灵活的SSL。一切工作,现在我想使用HTTPS对整个网站。我使用PHP的Apache Web服务器上。

I am using Cloudflare Flexible SSL on a website I programmed myself (no framework or CMS). Everything is working and now I want to use HTTPS on the whole site. I use PHP on Apache web server.

我想知道我应该怎么处理这和所有用户重定向到HTTPS。

I am wondering how I should approach this and redirect all users to HTTPS.

目前我的.htaccess设置是这样的:

Currently my .htaccess is set up like this:

# Force www.
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]

我见过<一个href=\"http://stackoverflow.com/questions/4083221/how-to-redirect-all-http-requests-to-https?lq=1\">this回答计算器上,但它指向这是不一样简单的

I have seen this answer on stackoverflow, but it points to another answer which is not as simple and doesn't recommend rewrites.

这是Apache推荐:

This is the Apache recommendation:

<VirtualHost *:80>
    ServerName www.example.com
    Redirect "/" "https://www.example.com/"
</VirtualHost >

<VirtualHost *:443>
    ServerName www.example.com
    # ... SSL configuration goes here
</VirtualHost >

但坦率地说,我不知道这意味着什么。

But frankly, I have no clue what this means.

我如何将用户重定向到HTTPS和WWW?什么我应该知道的,切换到HTTPS?

How can I redirect users to HTTPS and www? Anything I should be aware of, when switching to HTTPS?

推荐答案

最好的办法是使用CloudFlare的。

The best way is to use Cloudflare.

在CloudFlare的网站:

On the Cloudflare website:


  1. 转至页面细则上面的按钮

  2. 添加新的规则:始终使用https [ON]

或者你可以在使用的.htaccess

RewriteEngine On
# Redirect with www
RewriteCond %{HTTP_HOST} !^www\.example\.com [NC,OR]
# Redirect to https
#    With Cloudflare:
RewriteCond %{HTTP:CF-Visitor} '"scheme":"http"'
#    Without Cloudflare:
# RewriteCond %{HTTPS} off
RewriteRule ^ https://www.example.com%{REQUEST_URI} [NE,R=301,L]

这篇关于如何强制HTTPS(CloudFlare的灵活SSL)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 07:57