| 1 |
<?php |
<?php |
| 2 |
// $Id: globalredirect.module,v 1.1.2.4.2.15 2008/09/14 23:16:33 njt1982 Exp $ |
// $Id: globalredirect.module,v 1.1.2.4.2.16 2008/12/22 11:22:22 njt1982 Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 15 |
|
|
| 16 |
define('GLOBALREDIRECT_DESLASH_ENABLED', 1); |
define('GLOBALREDIRECT_DESLASH_ENABLED', 1); |
| 17 |
|
|
| 18 |
|
define('GLOBALREDIRECT_CASE_SENSITIVE_URLS_ENABLED', 1); |
| 19 |
|
|
| 20 |
/** |
/** |
| 21 |
* Implementation of hook_help(). |
* Implementation of hook_help(). |
| 22 |
*/ |
*/ |
| 80 |
|
|
| 81 |
// Trim any trailing slash off the end (eg, 'node/1/' to 'node/1') |
// Trim any trailing slash off the end (eg, 'node/1/' to 'node/1') |
| 82 |
$redirect_slash = variable_get('globalredirect_deslash', GLOBALREDIRECT_DESLASH_ENABLED) == GLOBALREDIRECT_DESLASH_ENABLED; |
$redirect_slash = variable_get('globalredirect_deslash', GLOBALREDIRECT_DESLASH_ENABLED) == GLOBALREDIRECT_DESLASH_ENABLED; |
| 83 |
$request = $redirect_slash ? trim($_GET['q'], '/') : $_GET['q']; |
$request = $redirect_slash ? trim($_REQUEST['q'], '/') : $_REQUEST['q']; |
| 84 |
|
|
| 85 |
// Optional stripping of "/0". Defaultly disabled |
// Optional stripping of "/0". Defaultly disabled |
| 86 |
switch (variable_get('globalredirect_trailingzero', GLOBALREDIRECT_FEATURE_DISABLED)) { |
switch (variable_get('globalredirect_trailingzero', GLOBALREDIRECT_FEATURE_DISABLED)) { |
| 101 |
// Check the path (eg, node/123) for an request. |
// Check the path (eg, node/123) for an request. |
| 102 |
$alias = drupal_get_path_alias($request); |
$alias = drupal_get_path_alias($request); |
| 103 |
|
|
| 104 |
|
// Alias case sensitivity check. If there is an alias from the previous lookup, do a query to test for case. |
| 105 |
|
if ($alias && variable_get('globalredirect_case_sensitive_urls', GLOBALREDIRECT_CASE_SENSITIVE_URLS_ENABLED) == GLOBALREDIRECT_CASE_SENSITIVE_URLS_ENABLED) { |
| 106 |
|
$alias_sensitive = db_result(db_query("SELECT dst FROM {url_alias} WHERE dst = '%s'", $alias)); |
| 107 |
|
|
| 108 |
|
if ($alias_sensitive && $alias != $alias_sensitive) { |
| 109 |
|
// There is a match and there is a difference in case. |
| 110 |
|
$alias = $alias_sensitive; |
| 111 |
|
} |
| 112 |
|
} |
| 113 |
|
|
| 114 |
// If alias is different to the request, redirect... |
// If alias is different to the request, redirect... |
| 115 |
if ($alias != $request) { |
if ($alias != $_REQUEST['q']) { |
| 116 |
drupal_goto($alias, $query_string, NULL, 301); |
drupal_goto($alias, $query_string, NULL, 301); |
| 117 |
} |
} |
| 118 |
|
|
| 119 |
// If the trimmed request differs to the request then redirect (basically, de-slash the source path). |
// If the trimmed request differs to the request then redirect (basically, de-slash the source path). |
| 120 |
if ($redirect_slash && ($request != $q)) { |
if ($redirect_slash && ($request != $_REQUEST['q'])) { |
| 121 |
drupal_goto($request, $query_string, NULL, 301); |
drupal_goto($request, $query_string, NULL, 301); |
| 122 |
} |
} |
| 123 |
|
|