HTTPS Force Redirect not working in Wordpress

前端 未结 2 1661
梦谈多话
梦谈多话 2021-02-01 07:39

My Wordpress directory is at www.example.com/blog

I recently changed my entire site to force HTTPS. So my .htaccess file in /blog/ looks like this:



        
2条回答
  •  刺人心
    刺人心 (楼主)
    2021-02-01 08:36

    You can also add these two lines to the wp-config.php

    define('WP_SITEURL', 'https://' . $_SERVER['HTTP_HOST']);
    define('WP_HOME', 'https://' . $_SERVER['HTTP_HOST']);
    

    So you could easily make conditions for http for dev environment and https for live like so:

    if(strpos($_SERVER['HTTP_HOST'], 'livedomain.com') !== FALSE){
      define('WP_SITEURL', 'https://' . $_SERVER['HTTP_HOST']);
      define('WP_HOME', 'https://' . $_SERVER['HTTP_HOST']);
    } else {
      define('WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST']);
      define('WP_HOME', 'http://' . $_SERVER['HTTP_HOST']);
    }
    

提交回复
热议问题