The tolerant base URL

Submitted by Bill St. Clair on Tue, 17 Jan 2006 19:50:59 GMT  <== Webmaster stuff ==> 

Drupal.org - a little trick I found that will allow me to support both http and https. It also stops Drupal from rewriting www.billstclair.com, or billstclair.nfshost.com, to billstclair.com. The details are only interesting for Drupal site administrators...

In your settings.php file, instead of a fixed string for the $base_url, use the following (three dots denote elided code):

<?php
...
$base_url = 'http' . (isset($_SERVER['HTTPS']) ? $_SERVER['HTTPS'] == 'on' ? 's' : '' : '');
$base_url .= '://' .$_SERVER['HTTP_HOST'];
if ($dir = trim(dirname($_SERVER['SCRIPT_NAME']), '\,/')) {
$base_url .= "/$dir";
}
...
?>

Add comment Edit post Add post