347dc5397c2dc12a11269639c0552e2dedb9c2e8 globalredirect.module | 36 +++++++++++++++++++----------------- 1 files changed, 19 insertions(+), 17 deletions(-) diff --git a/globalredirect.module b/globalredirect.module index 22a9f72..a7e4c0b 100644 --- a/globalredirect.module +++ b/globalredirect.module @@ -74,7 +74,15 @@ function globalredirect_init() { $path = isset($_REQUEST['q']) ? $_REQUEST['q'] : ''; language_url_rewrite($path, $options); } - $prefix = rtrim($options['prefix'], '/'); + $prefix = $options['prefix']; + // Allow custom_url_rewrite to do its thing. + if (function_exists('custom_url_rewrite_outbound')) { + custom_url_rewrite_outbound($prefix, $options, $path); + } + + // Trim any trailing slash off the end (eg, 'node/1/' to 'node/1') + $request = $settings['deslash'] ? trim($_GET['q'], '/') : $_GET['q']; + $prefix = $settings['deslash'] ? trim($prefix, '/') : $prefix; // Do a check if this is a front page if (drupal_is_front_page()) { @@ -86,21 +94,18 @@ function globalredirect_init() { // Redirect if the current request does not refer to the front page in the // configured fashion (with or without a prefix) if (isset($_REQUEST['q']) && $_REQUEST['q'] != $prefix) { - drupal_goto('', $query_string, NULL, 301); + drupal_goto($prefix, $query_string, NULL, 301); } elseif ($settings['nonclean_to_clean'] && ((bool)variable_get('clean_url', 0)) && (strpos(request_uri(), '?q=') || strpos(request_uri(), 'index.php'))) { - drupal_goto('', $query_string, NULL, 301); + drupal_goto($prefix, $query_string, NULL, 301); } // If we've got to this point then we're on a front page with a VALID // request path (such as a language-prefix front page such as '/de') return; } - // Trim any trailing slash off the end (eg, 'node/1/' to 'node/1') - $request = $settings['deslash'] ? trim($_GET['q'], '/') : $_GET['q']; - // Optional stripping of "/0". Disabled by default. switch ($settings['trailing_zero']) { case 2 : @@ -176,13 +181,6 @@ function globalredirect_init() { // Find an alias (if any) for the request $langcode = isset($options['language']->language) ? $options['language']->language : ''; $alias = drupal_get_path_alias($request, $langcode); - if (function_exists('custom_url_rewrite_outbound')) { - // Modules may alter outbound links by reference. - custom_url_rewrite_outbound($alias, $options, $request); - } - if ($prefix && $alias) { - $prefix .= '/'; - } // Alias case sensitivity check. If there is an alias from the previous // lookup, do a query to test for case. @@ -195,11 +193,15 @@ function globalredirect_init() { } } - // Compare the request to the alias. This also works as a 'deslashing' - // agent. If we have a language prefix then prefix the alias - if ($_REQUEST['q'] != $prefix . $alias) { + if (function_exists('custom_url_rewrite_outbound')) { + // Modules may alter outbound links by reference. + custom_url_rewrite_outbound($alias, $options, $request); + } + + // Compare the request to the alias. This also works as a 'deslashing' agent. + if ($_REQUEST['q'] != $alias) { // If it's not just a slash or user has deslash on, redirect - if (str_replace($prefix . $alias, '', $_REQUEST['q']) != '/' || $settings['deslash']) { + if (str_replace($alias, '', $_REQUEST['q']) != '/' || $settings['deslash']) { globalredirect_goto($alias, $query_string); } }