WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've got a WordPress install that is serving up content via both HTTP and HTTPS. The site URL is configured as "http://www.example.com". This works for most situations - if a person requests a page at "https://www.example.com/page" the page is served up via HTTPS.

However, the challenge that I'm facing is that there are a number of WordPress template functions which pull the site URL (like get_bloginfo('stylesheet') ) and when they do that, they include "http://" in the returned results. Similarly, images that are inserted in the WYSIWYG editor have the "http://www.example.com..." path hard coded.

What I'd really like to do is find a way to define the base site URL as "//www.example.com", which would hopefully make everything work correctly. However, the WordPress admin fields won't support this.

Does anyone have any ideas how to do this?

share|improve this question
    
As long as all of your paths are coming from wordpress and everything in your code is marked up with // and not http:// you should be fine. – hitautodestruct Nov 12 '13 at 7:15
    
This could also be an issue with the wordpress version you're using. I'm running 3.7.1 and things are working at full https. – hitautodestruct Nov 12 '13 at 7:17

An easy solution is to use .htaccess rules.

#Redirect HTTP to HTTPS
RewriteCond %{HTTPS} off
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]`
share|improve this answer

If you don't want to force HTTPS (or redirect all non-HTTPS requests) the URLs in posts can be handled like this:

function content_ssl($content) {
  if (isset($_SERVER["HTTPS"]))
    $content = ereg_replace("http://" . $_SERVER["SERVER_NAME"], "https://" . $_SERVER["SERVER_NAME"], $content);
  return $content;
}
add_filter('the_content', 'content_ssl');

WordPress itself handles protocol matching. Some plugins however do not.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.