With the Drupal system there are many places where links are generated. Some appear to go through the url function, while others do not.

When clean URLs are enabled, the site becomes broken in certain configurations. The problem is that the way links are generated causes Drupal to become dependent upon knowing the method by which users access the site. E.g., the same Drupal site cannot be made available to users over both http and https, or via different hostnames. This means that a particular configuration must be hard-coded to support only a limited class of users.

The problem is due to how clean URLs are generated. Clean URLs are specified as relative links, and a base tag is generated with a hard-coded $base_url. This is not the right way to do it.

The correct method is to have a variable (let's call it $base_prefix), which only hard-codes the path portion of the base URL. All links should be generated as $base_prefix . "/path/to/content" . The $base_url variable should only be used when posting links to the site externally, such as in account registration emails.

This is not a issue with non-clean URLs, because they are (by accident) robust. Clean URLs, however, are not robust. Please consider redesigning how links are generated in all aspects of Drupal.

Comments

jonbob’s picture

Title: Drupal link generation is non-robust when clean URLs are enabled » Allow multiple URI schemes for one Drupal site

I don't think "link generation is non-robust" is the way to phrase this. Changing to a title more descriptive of the feature request.

I believe having multiple configuration files is a simple workaround, at least for multiple hostnames, correct? Drupal can respond to multiple virtual hosts and direct them to different configuration files, which could be identical except for the value of $base_url. This may well not work for multiple schemes (http vs. https) though.

moshe weitzman’s picture

you can use whatever logic you wish to set the $base_url value. Here is one I use from time to time. You need to modify so http is not hardcoded.

$base_url = 'http://' . $_SERVER['SERVER_NAME']. '/'. trim(dirname($_SERVER['PHP_SELF']), '\,/');

mikegull’s picture

Follow-up on base URL, to set http:

if ((isset($_SERVER['HTTPS'])) AND (strtolower($_SERVER['HTTPS']) == "on")) {
   $http = "https://";
} else {
   $http = "http://";
}
$base_url = $http . $_SERVER['SERVER_NAME']. '/'. trim(dirname($_SERVER['PHP_SELF']), '\,/');