Commit 69726b0d authored by Steven Wittens's avatar Steven Wittens

#56634: Resolve issues with varying $base_url

- Fix locations links in watchdog
- Fix repeated subdirectory in page cache CIDs
parent 99e7c0ec
......@@ -51,6 +51,18 @@ DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine on
# If your site can be accessed both with and without the prefix www.
# you can use one of the following settings to force user to use only one option:
#
# If you want the site to be accessed WITH the www. only, adapt and comment out the following:
# RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
# RewriteRule .* http://www.example.com/ [L,R=301]
#
# If you want the site to be accessed only WITHOUT the www. , adapt and comment out the following:
# RewriteCond %{HTTP_HOST} !^example\.com$ [NC]
# RewriteRule .* http://example.com/ [L,R=301]
# Modify the RewriteBase if you are using Drupal in a subdirectory and
# the rewrite rules are not working properly.
#RewriteBase /drupal
......
......@@ -61,6 +61,9 @@ Drupal x.x.x, xxxx-xx-xx (development version)
* added support for external URLs.
- queue module:
* removed from core.
- HTTP handling:
* added support for a tolerant Base URL.
* output URIs relative to the root, without a base tag.
Drupal 4.6.6, 2006-03-13
------------------------
......
......@@ -80,7 +80,7 @@ function timer_stop($name) {
}
/**
* Locate the appropriate configuration file.
* Find the appropriate configuration directory.
*
* Try finding a matching configuration directory by stripping the website's
* hostname from left to right and pathname from right to left. The first
......@@ -108,7 +108,7 @@ function timer_stop($name) {
*
* 13. $confdir/default
*/
function conf_init() {
function conf_path() {
static $conf = '';
if ($conf) {
......@@ -131,6 +131,37 @@ function conf_init() {
return $conf;
}
/**
* Loads the configuration and sets the base URL correctly.
*/
function conf_init() {
global $db_url, $db_prefix, $base_url, $base_path, $base_root;
$conf = array();
require_once './'. conf_path() .'/settings.php';
if (isset($base_url)) {
// Parse fixed base URL from settings.php.
$parts = parse_url($base_url);
$base_path = isset($parts['path']) ? $parts['path'] . '/' : '/';
// Build $base_root (everything until first slash after "scheme://").
$base_root = substr($base_url, 0, strlen($base_url) - strlen($parts['path']));
}
else {
// Create base URL
$base_root = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 'https' : 'http';
$base_url = $base_root .= '://'. $_SERVER['HTTP_HOST'];
if ($dir = trim(dirname($_SERVER['SCRIPT_NAME']), '\,/')) {
$base_path = "/$dir";
$base_url .= $base_path;
$base_path .= '/';
}
else {
$base_path = '/';
}
}
}
/**
* Returns and optionally sets the filename for a system item (module,
* theme, etc.). The filename, whether provided, cached, or retrieved
......@@ -387,12 +418,12 @@ function cache_clear_all($cid = NULL, $wildcard = false) {
* get cached either.
*/
function page_get_cache() {
global $user, $base_url;
global $user, $base_root;
$cache = NULL;
if (!$user->uid && $_SERVER['REQUEST_METHOD'] == 'GET' && count(drupal_set_message()) == 0) {
$cache = cache_get($base_url . request_uri());
$cache = cache_get($base_root . request_uri());
if (empty($cache)) {
ob_start();
......@@ -589,11 +620,14 @@ function request_uri() {
* A link to associate with the message.
*/
function watchdog($type, $message, $severity = WATCHDOG_NOTICE, $link = NULL) {
global $user;
global $user, $base_root;
$current_db = db_set_active();
db_query("INSERT INTO {watchdog} (uid, type, message, severity, link, location, referer, hostname, timestamp) VALUES (%d, '%s', '%s', %d, '%s', '%s', '%s', '%s', %d)", $user->uid, $type, $message, $severity, $link, request_uri(), referer_uri(), $_SERVER['REMOTE_ADDR'], time());
// Note: log the exact, entire absolute URL.
$request_uri = $base_root . request_uri();
db_query("INSERT INTO {watchdog} (uid, type, message, severity, link, location, referer, hostname, timestamp) VALUES (%d, '%s', '%s', %d, '%s', '%s', '%s', '%s', %d)", $user->uid, $type, $message, $severity, $link, $request_uri, referer_uri(), $_SERVER['REMOTE_ADDR'], time());
if ($current_db) {
db_set_active($current_db);
......@@ -686,13 +720,10 @@ function _drupal_bootstrap($phase) {
switch ($phase) {
case DRUPAL_BOOTSTRAP_DATABASE:
global $db_url, $db_prefix, $base_url, $base_path;
$conf = array();
require_once './' . conf_init() .'/settings.php';
require_once './includes/database.inc';
// Initialize the configuration
conf_init();
// Initialize the default database.
$parts = parse_url($base_url);
$base_path = (isset($parts['path']) ? $parts['path'] . '/' : '/');
require_once './includes/database.inc';
db_set_active();
break;
......
......@@ -1322,7 +1322,7 @@ function _drupal_bootstrap_full() {
* @see drupal_page_header
*/
function page_set_cache() {
global $user, $base_url;
global $user, $base_root;
if (!$user->uid && $_SERVER['REQUEST_METHOD'] == 'GET') {
// This will fail in some cases, see page_get_cache() for the explanation.
......@@ -1342,7 +1342,7 @@ function page_set_cache() {
}
ob_end_flush();
if ($cache && $data) {
cache_set($base_url . request_uri(), $data, CACHE_TEMPORARY, drupal_get_headers());
cache_set($base_root . request_uri(), $data, CACHE_TEMPORARY, drupal_get_headers());
}
}
}
......
......@@ -673,7 +673,7 @@ function system_default_region($theme) {
* An array of file objects of the specified type.
*/
function system_listing($mask, $directory, $key = 'name', $min_depth = 1) {
$config = conf_init();
$config = conf_path();
$searchdir = array($directory);
$files = array();
......
......@@ -673,7 +673,7 @@ function system_default_region($theme) {
* An array of file objects of the specified type.
*/
function system_listing($mask, $directory, $key = 'name', $min_depth = 1) {
$config = conf_init();
$config = conf_path();
$searchdir = array($directory);
$files = array();
......
......@@ -87,9 +87,14 @@
$db_prefix = '';
/**
* Base URL:
* Base URL (optional).
*
* The URL to your Drupal installation.
* If you are experiencing issues with different site domains,
* uncomment the Base URL statement below (remove the leading hash sign)
* and fill in the URL to your Drupal installation.
*
* You might also want to force users to use a given domain.
* See the .htaccess file for more information.
*
* Examples:
* $base_url = 'http://www.example.com';
......@@ -100,7 +105,7 @@
* It is not allowed to have a trailing slash; Drupal will add it
* for you.
*/
$base_url = 'http://www.example.com'; // NO trailing slash!
# $base_url = 'http://www.example.com'; // NO trailing slash!
/**
* PHP settings:
......@@ -132,10 +137,12 @@
* useful in a configuration file for a vhost or directory, rather than
* the default settings.php. Any configuration setting from the 'variable'
* table can be given a new value.
*
* Remove the leading hash signs to enable.
*/
//$conf = array(
// 'site_name' => 'My Drupal site',
// 'theme_default' => 'pushbutton',
// 'anonymous' => 'Visitor'
//);
# $conf = array(
# 'site_name' => 'My Drupal site',
# 'theme_default' => 'pushbutton',
# 'anonymous' => 'Visitor'
# );
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment