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 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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Pwm双极模式H桥驱动控制电机
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题