Configure a Working SSL Subdomain on WordPress While Still Using CloudFlare

CloudFlare and Securing WordPress Admin

I’ve recently been using CloudFlare on this blog for performance, security, and bandwidth and spam comment reduction. I also recently made the switch to Linode so I now have full control of my server. I wanted to secure my WordPress admin login page but since I use the free version of CloudFlare, I had to put SSL on a subdomain.

Secured Subdomain with Mangled Webpages

Once I had setup the secure subdomain, I noticed that none of the pages loaded correctly; just text. I later figured out that the reason is because WordPress 3.0 rewrites all urls to https when viewed under https. That meant that it was trying to request https URLs for things like CSS, images, etc from CloudFlare and not the subdomain. I tried all types of mod_rewrite combinations to no avail.

The Solution

The solution is really simple. All you need to do is install the WordPress HTTPS Plugin and configure the following settings:

  • SSL Host: secure.yoursite.com
  • Check Force SSL Administration

With the recent update of the plugin to version 2.0, you need to actually edit the plugin because it does not rewrite the wp-login.php page.

Change this:

// Fix admin_url on login page
if ( $GLOBALS['pagenow'] == 'wp-login.php' && $this->is_ssl() ) {
	add_filter('site_url', array(&$this, 'replace_http_url'));
}

To this:

// Fix admin_url on login page
if ( $GLOBALS['pagenow'] == 'wp-login.php' && $this->is_ssl() ) {
	add_filter('site_url', array(&$this, 'replace_http_url'));
	add_filter('admin_url', array(&$this, 'replace_http_url'));
}

Feel free to post a comment if you have an questions!

9 Comments Configure a Working SSL Subdomain on WordPress While Still Using CloudFlare

  1. Retroy

    Hi Dustin, thanks for sharing your experience. I’m exactly in the same situation, I want to access wp-admin over ssl with the free version of CloudFlare using the https://direct. subdomain.

    I have follow your solution exactly as described, but it’s not working for me, when I try to login it makes a redirection to wp-admin and another to wp-login.php again but is not entering in the admin area.

    Do you have any clue or suggestion?

    Thanks in advance.

    Reply
    1. Dustin

      Hey sorry to here it’s not working – have you set up your https redirect in your .htaccess or Apache site config? When you reach the wp-login.php page, what is the redirect_to= parameter? It should look like this: redirect_to=https%3A%2F%2Fsecure.yoursite.com%2Fwp-admin%2F

      Reply
  2. Pingback: Site With The Lamp » Cloudflare and Wordpress Admin

    1. Dustin Schultz

      James, you generate your SSL certificate. A self-signed cert is free and fine for personal use. Depending on your setup, you may need to open port 443 on your firewall. Then you configure the plugin as detailed in the post. That’s all.

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>