Why don't links use https:// when I access the site using that protocol? The Problem

Accessing my site over https (the only protocol allowed) I get the content, but none of the CSS, images etc.

Drupal is creating pages in response to https requests that include http links to these resources, but it should be using https.

What I've done

I have copied a site to a dev server. The site loads and basically works fine - I can log in etc. It's just that all the links drupal generates are http. The site I've copied it from also runs over https. The site does not exist on http (it would just get a Forbidden error). I've drush cc all.

So Apache's working - I can access the site. .htaccess is working (clean urls work, for example).

I'm using SNI to access the site because the server has other vhosts too, but I'm only accessing the site using the latest Firefox (and as it's a dev site and I'm the only dev, nobody else will use it).

I've done this dozens of times and am quite stumped! Why does Drupal not notice that the request came over https?

The fix

Turns out that .htaccess has this to say:


/* Base URL (optional).                                                        

If Drupal is generating incorrect URLs on your site, which could            
be in HTML headers (links to CSS and JS files) or visible links on pages    
(such as in menus), uncomment the Base URL statement below (remove the      
leading hash sign) and fill in the absolute URL to your Drupal installation.



Sure enough, putting $base_url = 'https://example.com'; fixed it.

But why is this necessary?
I had a similar problem and ended up using $base_url = ''. It fixes the problem with static content. Drupal will generate relative URLs instead of absolute which is the right thing to do anyway. However, this breaks update.php for some reasons (running 7.38).