summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteven Wittens <steven@10.no-reply.drupal.org>2006-04-12 08:42:47 +0000
committerSteven Wittens <steven@10.no-reply.drupal.org>2006-04-12 08:42:47 +0000
commit69726b0d7b7741122ded6994692ff24173a7caee (patch)
treec64d5c91ffad08f10dbeb1e6e11a838284c1d1d3
parent99e7c0ec7c630dde981cb5ee7c046e71833cfd50 (diff)
downloadbrdo-69726b0d7b7741122ded6994692ff24173a7caee.tar.gz
brdo-69726b0d7b7741122ded6994692ff24173a7caee.tar.bz2
#56634: Resolve issues with varying $base_url
- Fix locations links in watchdog - Fix repeated subdirectory in page cache CIDs
-rw-r--r--.htaccess12
-rw-r--r--CHANGELOG.txt3
-rw-r--r--includes/bootstrap.inc55
-rw-r--r--includes/common.inc4
-rw-r--r--modules/system.module2
-rw-r--r--modules/system/system.module2
-rw-r--r--sites/default/settings.php23
7 files changed, 77 insertions, 24 deletions
diff --git a/.htaccess b/.htaccess
index 16193a2a0..df1209ccb 100644
--- a/.htaccess
+++ b/.htaccess
@@ -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
diff --git a/CHANGELOG.txt b/CHANGELOG.txt
index f30b472c7..96252d4ee 100644
--- a/CHANGELOG.txt
+++ b/CHANGELOG.txt
@@ -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
------------------------
diff --git a/includes/bootstrap.inc b/includes/bootstrap.inc
index 0d2fc1f9e..25fd7a5e3 100644
--- a/includes/bootstrap.inc
+++ b/includes/bootstrap.inc
@@ -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) {
@@ -132,6 +132,37 @@ function conf_init() {
}
/**
+ * 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
* from the database, is only returned if the file exists.
@@ -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;
diff --git a/includes/common.inc b/includes/common.inc
index f02911b44..368aa64fe 100644
--- a/includes/common.inc
+++ b/includes/common.inc
@@ -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());
}
}
}
diff --git a/modules/system.module b/modules/system.module
index 08b40091d..8f2907882 100644
--- a/modules/system.module
+++ b/modules/system.module
@@ -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();
diff --git a/modules/system/system.module b/modules/system/system.module
index 08b40091d..8f2907882 100644
--- a/modules/system/system.module
+++ b/modules/system/system.module
@@ -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();
diff --git a/sites/default/settings.php b/sites/default/settings.php
index 96d49bc5c..bb8c0ab32 100644
--- a/sites/default/settings.php
+++ b/sites/default/settings.php
@@ -87,9 +87,14 @@ $db_url = 'mysql://username:password@localhost/databasename';
$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 @@ $db_prefix = '';
* 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 @@ ini_set('url_rewriter.tags', '');
* 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'
+# );