2

I have a rather large site where the site builders have all of the internal paths automatically set to lowercase (in the pages themselves, menus, etc.). At the moment, we have other sites linking to the old (capitalized) version of several hundred to possibly 1,000+ nodes in the new D7 version of the site.

So a link to http://www.example.com/alzheimers works fine, but if I manually enter http://www.example.com/Alzheimers I get taken to our custom 404 (with our Drupal theme showing the message). This is a problem as it's a high visibility site with a lot of external links to the old URLs.

The sitebuilders also attempted to manually enter a redirect of /Alzheimers/alzheimers and, of course, this created an infinite redirect loop, black hole, zombie war, etc.

I attempted to handle this with apache "mod_speling", with no success, though I don't have extensive experience with this mod. I am wondering if I am possibly missing something / does it need specific rule for capitalization changes? The instructions I followed had me enable the mod and restart Apache. It didn't help.

So I'm wondering if I need to hook into the theme (hook_init?) to grab the requested URL and throw in a little PHP to just set the string to lower. Any ideas? I don't have any problems coding it, but if there is a simpler way to handle this, any help would be tremendously appreciated.

Being as this would be a typical issue for any site written for Windows and transferred to Drupal or LAMP in general, I can't possibly be the first person to need a fix for this.

If custom Drupal code is needed, where is best to hook it in for something like this?

unor
  • 92,415
  • 26
  • 211
  • 360
amatusko
  • 348
  • 2
  • 14

1 Answers1

1

I think hook_init() would get called too late in the process (the bootstrap has already been done and the path resolved by that point). You might want to try hook_boot() instead:

function mymodule_boot() {
  $_GET['q'] = strtolower($_GET['q']);
}

Once you've installed the module pop into the system table and set the weight column for your module to -1 to ensure your hook gets called before any other modules' hooks. Then flush Drupal's caches and you should be good to go.

Beware though, search engines will see http://www.example.com/alzheimers and http://www.example.com/Alzheimers as two separate pages with duplicate content. Ideally you'd want to do a 301 redirect from the old page to new, but this would be a lot more complicated and (I think) would involve implementing hook_url_inbound_alter.

Clive
  • 36,918
  • 8
  • 87
  • 113
  • outstanding answer. I was also considering using hook_boot, but I think I had read somewhere that one of the two didn't run on cached pages or something, hence why I thought hook_init would be a better option. – amatusko Dec 22 '11 at 05:25
  • Ugh. Sorry I'm new to this format. Lost edits. I like the approach to re-ordering the module to the top+1. I wish I had enough repz to upvote your answer.\n So I have a request that should be coming in to my server via apache, yet it is apparently being intercepted by Drupal before that or something, which is impossible, since drupal runs inside php which runs inside apache (so to speak). I can't understand how drupal could overwrite my server's settings. (cont'd) – amatusko Dec 22 '11 at 05:33
  • Ironically, when a site builder tried to use drupal's mod system to add a redirect from the /Alz page to the /alz page, he got the good old infinite redirect loop error business. – amatusko Dec 22 '11 at 05:33