We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 8109
    • 128 Posts
    I'm expecting some type-in traffic to a page I've set up, and I've realized that it's going to be essential that urls be treated as case insensitve. I've read extensivly on this now, but I can't seem to get capitals in a typed-in url to be treated as lower case.

    Here: http://wiki.modxcms.com/index.php/Friendly_URLs_Guide#Non_case-sensitive_urls
    we learn that the htaccess file can be modified to make this work, but it doesn't for me.

    Another option involved access to the httpd.conf file, which is not an option with my hosting service.

    I've found snippets for Evo that do not work with Revo.

    I found a snippet for Revo that didn't work, either.

    I wonder if this is a common problem, and if there's a common solution.

    Revo 2.2.0-pl2 [ed. note: drwagner13 last edited this post 14 years, 2 months ago.]
      Revo 2.0.8-pl
      • 3749
      • 24,544 Posts
      AFAIK, this is quite difficult without access to httpd.conf. I did once see a solution involving rewrite rules that rewrote every capitalized letter as lowercase.

      One solution (I think) would be to put a snippet on your error (page-not-found) page that converts the url to lowercase if it contains any uppercase letters, and forwards the user to it with:

      $modx->sendRedirect();


      You can't just forward to the lowercase version without checking to see if the URL has uppercase letters or you'll get an infinite loop.

      You could also do that with a plugin attached to OnPageNotFound.


      Of course there's the brute force method, which is to install the LogPageNotFound plugin and add a new rewrite rule to .htaccess for each error. wink


      Come to think of it, a few extra lines in the LogPageNotFound plugin might be able to do it for you. If I get time, I'll check.



      ------------------------------------------------------------------------------------------
      PLEASE, PLEASE specify the version of MODX you are using.
      MODX info for everyone: http://bobsguides.com/modx.html [ed. note: BobRay last edited this post 14 years, 6 months ago.]
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 8109
        • 128 Posts
        Thanks Bob, I wish there was a straightforward method... I'll look into the plugin option again. It should be the best way to go, but I don't think I have the php chops to do it right now.
          Revo 2.0.8-pl
          • 3749
          • 24,544 Posts
          Try this:

          Create a plugin called CaseInsensitiveUrls with this code:

          <?php
          $url = $_SERVER['REQUEST_URI'];
          
          if (preg_match('~[A-Z]~', $url)) {
              $modx->sendRedirect(strtolower($url));
          }


          On the System Events page, connect it to OnPageNotFound with a priority of 3.

          Save it.

          Note that this will only work if FURLs are on and all aliases and $_GET parameters on the site are all lowercase. When a page is not found, it converts *everything* in the url to lowercase and forwards the user. Of course, if the page *is* found, this code won't execute so it shouldn't affect internal $_GET values on the site.


          ------------------------------------------------------------------------------------------
          PLEASE, PLEASE specify the version of MODX you are using.
          MODX info for everyone: http://bobsguides.com/modx.html

          [ed. note: BobRay last edited this post 14 years, 6 months ago.]
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
            • 3749
            • 24,544 Posts
            Here is a better version that leaves any $_GET parameters alone:


            <?php
            $url = $_SERVER['REQUEST_URI'];
            $pieces = explode('?', $url);
            
            if (preg_match('~[A-Z]~', $pieces[0])) {
                $pieces[0] = strtolower($pieces[0]);
                $url = $pieces[0];
                $url  .= isset($pieces[1])? '?' . $pieces[1] : '';
                $modx->sendRedirect($url);
            }


            In case you're wondering why the priority should be set to 3, it's so it will execute before the LogPageNotFound plugin and after any bot-blocking plugins.


            ------------------------------------------------------------------------------------------
            PLEASE, PLEASE specify the version of MODX you are using.
            MODX info for everyone: http://bobsguides.com/modx.html [ed. note: BobRay last edited this post 13 years, 9 months ago.]
              Did I help you? Buy me a beer
              Get my Book: MODX:The Official Guide
              MODX info for everyone: http://bobsguides.com/modx.html
              My MODX Extras
              Bob's Guides is now hosted at A2 MODX Hosting
              • 8109
              • 128 Posts
              Brilliant, works perfectly. Thank you!!!
                Revo 2.0.8-pl
                • 3749
                • 24,544 Posts
                Glad it worked. Thanks for reporting back. smiley

                I'll probably add that as an option in the LogPageNotFound packages at some point.


                ------------------------------------------------------------------------------------------
                PLEASE, PLEASE specify the version of MODX you are using.
                MODX info for everyone: http://bobsguides.com/modx.html
                  Did I help you? Buy me a beer
                  Get my Book: MODX:The Official Guide
                  MODX info for everyone: http://bobsguides.com/modx.html
                  My MODX Extras
                  Bob's Guides is now hosted at A2 MODX Hosting