diff --git a/redirect.admin.inc b/redirect.admin.inc index ffc9aeb..95d946b 100644 --- a/redirect.admin.inc +++ b/redirect.admin.inc @@ -724,6 +724,12 @@ function redirect_settings_form($form, &$form_state) { '#title' => t('Allow redirections on admin paths.'), '#default_value' => variable_get('redirect_global_admin_paths', 0), ); + $form['globals']['redirect_global_case_sensitive'] = array( + '#type' => 'checkbox', + '#title' => t('Case-sensitive URL checking'), + '#description' => t('If enabled, the module will compare the current URL to the alias stored in the system. If there are any differences in case, then the user will be redirected to the correct URL.'), + '#default_value' => variable_get('redirect_global_case_sensitive', 0), + ); if (module_exists('locale')) { $form['globals']['redirect_global_language_prefix'] = array( '#type' => 'checkbox', diff --git a/redirect.install b/redirect.install index 6fb580e..d6ac5b0 100644 --- a/redirect.install +++ b/redirect.install @@ -459,7 +459,6 @@ function _redirect_migrate_global_redirect_variables() { // module: // - trailing_zero. // - menu_check. - // - case_sensitive_urls. // - language_redirect. // - canonical. // - content_location_header. @@ -473,6 +472,7 @@ function _redirect_migrate_global_redirect_variables() { 'redirect_global_canonical_front' => 'frontpage_redirect', 'redirect_global_deslash' => 'deslash', 'redirect_global_admin_paths' => 'ignore_admin_path', + 'redirect_global_case_sensitive' => 'case_sensitive_urls', ); // Migrate these but invert the value. diff --git a/redirect.module b/redirect.module index c2ec7ea..81799be 100644 --- a/redirect.module +++ b/redirect.module @@ -258,8 +258,14 @@ function redirect_url_inbound_alter(&$path, $original_path, $path_language) { return redirect_redirect((object) array('redirect' => '', 'type' => 'global')); } - // Redirect to the canonical URL. + // If the alias and the request path are case-insensitive the same, and case + // sensitivity is off, then reset the alias to the original request_path. $alias = drupal_get_path_alias($path, $path_language); + if (strcasecmp($alias, request_path()) == 0) { + $alias = variable_get('redirect_global_case_sensitive', 0) ? $alias : request_path(); + } + + // Redirect to the canonical URL. if ((!$is_front_page && variable_get('redirect_global_canonical', 1) || $is_front_page && variable_get('redirect_global_canonical_front', 0)) && $alias != $path diff --git a/redirect.test b/redirect.test index 33c6d23..9e11ce7 100644 --- a/redirect.test +++ b/redirect.test @@ -284,4 +284,22 @@ class RedirectFunctionalTest extends RedirectTestHelper { $this->drupalPost("admin/config/search/redirect/edit/{$redirect->rid}", $edit, t('Save')); $this->assertRedirect($redirect); } + + function testCaseSensitiveUrls() { + // Create a page node with a path alias. + $node = $this->drupalCreateNode(array('type' => 'page', 'path' => array('alias' => 'test-node'))); + + // If case sensitivity is on, redirect to the proper alias. + variable_set('redirect_global_case_sensitive', 1); + $case_sensitive_redirect = new stdClass(); + redirect_object_prepare($case_sensitive_redirect, array( + 'source' => 'Test-Node', + 'redirect' => 'test-node', + )); + $this->assertRedirect($case_sensitive_redirect); + + // If case sensitivity is off, don't redirect. + variable_set('redirect_global_case_sensitive', 0); + $this->assertNoRedirect($case_sensitive_redirect); + } }