0

I have inherited a website where the URLs contain capitalization, but the file structure on the server is all lowercase. This wasn't an issue until moving the site over to Apache.

I don't want to redirect the existing pages to a lowercase structure because the site is aged and ranking well on Google and Bing.

I've implemented mod_speling in my .htaccess by:

<IfModule mod_speling.c>
    CheckCaseOnly on
    CheckSpelling on
</IfModule>

However it re-writes all URLs to lowercase, which in the eyes of Google is a new URL.

Is there any way for me to treat all URLs as case insensitive whilst preserving the original URL?

For example: domain.com/Folder1/folder.htm would resolve to the same place as domain.com/folder1/Folder.htm?

Veera Nagireddy
  • 523
  • 2
  • 6

1 Answers1

3

You could use mod_rewrite to rewrite all your requests to lowercase. That might look like:

RewriteEngine On
RewriteMap lc int:tolower
RewriteRule ^(.*) ${lc:$1}

Given these files on disk:

$ ls
file1.txt  file2.txt  file3.txt  index.html

And these links in index.html:

<ul>
  <li><a href="File1.txt">File1</a></li>
  <li><a href="FILE2.txt">FILE2</a></li>
  <li><a href="file3.txt">file3</a></li>
</ul>

The rewrite configuration I've shown allows all three links to retrieve the expected file. The rewriting does not generate any sort of redirect to the client, so the client (e.g., Google) is not aware of the rewrite.

larsks
  • 43,623
  • 14
  • 121
  • 180