Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

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_spelling on my list of redirects so people could continue to type in a URL however they choose and it would continue to work. Mod_spellin, 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?

share|improve this question

migrated from stackoverflow.com Feb 14 '12 at 21:24

This question came from our site for professional and enthusiast programmers.

    
Thanks, I just re-posted it over there. –  Cloudkiller Feb 13 '12 at 16:50
    
When the list gets this long, it's time do dust off a standard RewriteMap template with a prg: script. Perl will do fine as a language. The easiest thing to do is to keep all of your fix-ups in a D/B and keep a local cache in a Hash in your Perl mapper. If you want some more details, I can post a more specific answer. This sort of solution is just as appropriate here. –  TerryE Feb 13 '12 at 16:57
1  
I spent the morning reading about RewriteMaps and I'm mostly convinced that I could just put the fix-ups in a DBM hash file. What would be the advantage of using a prg: script? –  Cloudkiller Feb 13 '12 at 18:36
    
It would be more useful if you put your update as an answer and then flagged it to go to webmasters as I think that's a better fit. –  paulmorriss Feb 14 '12 at 11:16
    
I did as you suggested paul. Thanks –  Cloudkiller Feb 14 '12 at 20:49

1 Answer 1

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.