dongmo2324
2011-12-21 16:02 阅读 26
已采纳

新Drupal站点的大写外部链接获得404

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?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

  • 已采纳
    doumu9019 doumu9019 2011-12-21 17:37

    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.

    点赞 评论 复制链接分享

相关推荐