Drupal 7 and url

For some reason, Drupal 7 skips loading addresses with addresses in different cases, even if lowercase addresses are enabled by default, so in fact the same page could be loaded under different addresses, for example - domain.com/contacts  domain.com/Contacts  domain.com/conTacts. To fix this, just add the following code to the central index.php file at the very beginning:

$request_uri = $_SERVER['REQUEST_URI'];
$path = parse_url($request_uri, PHP_URL_PATH);
if (preg_match('/[A-Z]/', $path)) {
  $lower_uri = strtolower($path);
  $query = isset($_SERVER['QUERY_STRING']) && $_SERVER['QUERY_STRING'] ? '?' . $_SERVER['QUERY_STRING'] : '';
  header("Location: " . $lower_uri . $query, true, 301);
  exit;
}

Add new comment

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.
The comment language code.