dsogx84602 2017-07-25 12:01
浏览 65
已采纳

WordPress SSL通过Cloudflare重定向

I have added my website to Cloudflare for use of flexible SSL. Everything on static content is ok. For example, I can access my files directly with https (Ex: https://www.samanik.com/logo.png). but I can't access the WordPress site. I have changed both the site_url and home_url in the db. I have added codes to .htaccess, but when I type my website without https it redirects to https (as I want). But, nothing is shown there. I get an error called ERR_TOO_MANY_REDIRECTS I don't know how to fix this problem.

Here is my .htaccess content.

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

<IfModule mod_rewrite.c>
 RewriteCond %{HTTPS} off
 RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
 RewriteCond %{HTTP_HOST} !^www\.
 RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>

Can anyone help me?

  • 写回答

2条回答 默认 最新

  • dongyuying1507 2017-07-25 17:43
    关注

    You can redirect to HTTPS using action hook as well.

    Add the below code in your **functions.php**:

    function redirectToHTTPS(){
     if($_SERVER['HTTPS']!="on"){
       $redirect= "https://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
        header("Location:$redirect");   
    }}
    add_action('init','redirectToHTTPS' );
    

    For detailed guide, check here.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 算能的sail库的运用
  • ¥15 'Content-Type': 'application/x-www-form-urlencoded' 请教 这种post请求参数,该如何填写??重点是下面那个冒号啊
  • ¥15 找代写python里的jango设计在线书店
  • ¥15 请教如何关于Msg文件解析
  • ¥200 sqlite3数据库设置用户名和密码
  • ¥15 AutoDL无法使用docker install吗?
  • ¥15 cups交叉编译后移植到tina sdk的t113,只需要实现usb驱动打印机,打印pdf文件
  • ¥30 关于#wireshark#的问题:需要网络应用流量数据集需要做长度序列的实验,需要与应用产生的会话的数据包的长度,如视频类或者聊天类软件
  • ¥15 根据上述描述表示泥浆密度沿着管路的长度方向在不断变化,如何来表示泥浆密度随管路的变化(标签-matlab|关键词-流计算)
  • ¥21 matlab可以把图像数据转换为小波分析吗