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 使用ESP8266连接阿里云出现问题
  • ¥15 被蓝屏搞吐了,有偿求帮解答,Ai回复直接拉黑
  • ¥15 BP神经网络控制倒立摆
  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
  • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并