3

I have a big website (15,000 pages) with a log list of redirects (about 800) that have been used in marketing pieces for years. My Apache server has been running mod_rewrite for the past 10 years or so to force all requests to lower case. So a user could put in /CamelCase and Apache would read it as /camelcase and my corresponding redirect would work.

I'm switching over my site to Drupal at the end of the month and the server needs to become case sensitive. I assumed that I could use mod_speling on my list of redirects so people could continue to type in a URL however they choose and it would continue to work. mod_speling, however, does not scan through the list of redirects so it does not work.

I have enough staff to have them go through the list of redirects and add in any case-sensitive variants but this would make my already large listing of redirects grow by 2 to 4 times. Hopefully I don't have to go down that route. I thought there might be a way to use mod_rewrite to test different cases on redirects but I can't get anything to work.

So, does anyone have ideas?

MrWhite
  • 43,224
  • 4
  • 50
  • 90
Cloudkiller
  • 191
  • 6

2 Answers2

4

After some research, I'm pretty sure that I'll just use a RewriteMap that will contain all of case variants. It will take some work to create most of the possibilities people might type in but as long as I can hit 90% of them I'll consider that a success. For those with similar issues, I'll document how it is done.

Start by creating the rewrite map file. This is just a text file on the server with the case variants listed.

## case_variants.txt

CamelCase camelcase CAMELCASE camelcase

Since this is a list I won't need to update often, I converted it to a DBM hash file so Apache can index it and get to the desired key faster. To do this, this command was run on the server as root.

$ httxt2dbm -i /etc/httpd/case_variants.txt -o /etc/httpd/case_variants.map 

Now I update the Apache directives to check this map file and re-write the request as needed. Note that this statement cannot be in a directory statement.

RewriteEngine on
  RewriteMap case2check dbm:/etc/httpd/case_variants.map 
  # if I wanted to use the text file instead, uncomment the following line
  # RewriteMap case2check txt:/etc/httpd/case_variants.txt
  RewriteRule ^/(.*)$ /${case2check:$1|$1} [PT]

All of this, and more, is explained on the Apache rewrite map page. If I missed anything or my process could be improved upon post it below.

MrWhite
  • 43,224
  • 4
  • 50
  • 90
Cloudkiller
  • 191
  • 6
2

A "lowercase" mapping can be applied first to the key passed to the rewrite map.

RewriteMap permredirects "dbm:/path/to/dbm/file.map"
RewriteMap lowercase int:tolower
RewriteCond ${permredirects:${lowercase:$1}} !=""
RewriteRule ^(.*) "${permredirects:${lowercase:$1}}" [L,R=301]
Connor Clark
  • 121
  • 1