We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 7205
    • 9 Posts
    Hi. I’m on MODx 0.9.5, FreeBSD 6.0, Apache2 and adding ’NC’ to my .htaccess as per the comments in that file do not make my URLs non case-sensitive. What gives? Here’s the first several lines of my .htaccess:

    AddType application/x-httpd-php .html .htm


    # MODx supports Friendly URLs via this .htaccess file. You must serve web
    # pages via Apache with mod_rewrite to use this functionality, and you must
    # change the file name from ht.access to .htaccess.
    #
    # Make sure RewriteBase points to the directory where you installed MODx.
    # E.g., "/modx" if your installation is in a "modx" subdirectory.
    #
    # You may choose to make your URLs non-case-sensitive by adding a NC directive
    # to your rule: RewriteRule ^(.*)$ index.php?q=$1 [L,QSA,NC]

    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?q=$1 [L,QSA,NC]
      • 7205
      • 9 Posts
      This is what happens when I use case that isn’t consistent with the page’s alias (ex: Home instead of home):

      « MODx Parse Error »
      MODx encountered the following error while attempting to parse the requested resource:
      « Too many forward attempts. »
      SQL: The request could not be completed due to too many unsuccessful forward attempts.
      [Copy SQL to ClipBoard]

      Parser timing
      MySQL: 0.0122 s (15 Requests)
      PHP: 0.0164 s
      Total: 0.0286 s
        • 23491 ☆ A M B ☆
        • 1,056 Posts
        I hadn’t tested this recently myself, but when I pass a URL w/ UPPERCASE, etc I get sent to the defined 404 page. Granted, I am using SEO Strict URL plugin...

        I would recommend, at a minimum, possibly trying the SEO Strict URL plugin (or disabling [NC] parameter?) to at least prevent multiple forwarding attempts/MODx error. Weird, hadn’t seen that one before...

        Has anyone else been successful in getting case-insensitive Friendly URLs to work?

        IMHO, I would not want mysite.com/Portofolio and mysite.com/portfolio to be treated the same. I’m thinking more SEO then I am user experience here, but personally I would prefer/Portoflio to be 301 redirected to /portfolio.

        Update:
        Whether I have "SEO Strict URLs" plugin active or not, or pass the [NC] parameter or not, I am always taken to my 404 page... (MODx v0.9.6)
          Mike Reid - www.pixelchutes.com
          MODx Ambassador / Contributor
          [Module] MultiMedia Manager / [Module] SiteSearch / [Snippet] DocPassword / [Plugin] EditArea / We support FoxyCart
          ________________________________
          Where every pixel matters.
          • 22303 MODX Staff
          • 10,725 Posts
          Confirmed; looks like we need to add a config setting to indicate if you want case-insensitive URLs, and the processing can be made to respect that optionally. In the meantime, here is a plugin that will make case-insensitive URLs work; just check the OnWebPageInit and OnPageNotFound events.

          <?php
          /**
           * A MODx plugin to redirect URLs with incorrect case to actual URL.
           */
          $alias= null;
          if ($modx->config['friendly_alias_urls'] == 1) {
              if (($modx->config['use_alias_path'] == 1 && $modx->documentMethod == 'alias' && $modx->event->name == 'OnPageNotFound')) {
                  $alias= (strlen($modx->virtualDir) > 0 ? $modx->virtualDir . '/' : '') . $modx->documentIdentifier;
              }
              elseif ($modx->event->name == 'OnWebPageInit') {
                  $alias= $modx->getDocumentIdentifier('alias');
              }
          }
          if ($alias) {
              if (!isset ($modx->documentListing[$alias])) {
                  $documentListingNC= array_change_key_case($modx->documentListing);
                  if (isset ($documentListingNC[strtolower($alias)])) {
                      $actualDocId= $documentListingNC[strtolower($alias)];
                      $modx->sendRedirect($modx->makeUrl($actualDocId), 0, '', 'HTTP/1.0 301 Moved Permanently');
                      exit();
                  }
              }
          }
          ?>

          NOTE: PHP tags included for syntax highlighting only -- don’t forget to remove them before pasting into the plugin editor.
            • 23491 ☆ A M B ☆
            • 1,056 Posts
            Well done! I will test this now (in addition to SEO Strict URL, too)...

            I assume that the [NC] parameter in .htaccess would STILL be required for handling of non-MODx served pages...

            e.g. mydomain.com/CuStOm_ScRiPt.php

            Update:

            I copied the code (omitting <?php and ?>), checked off corresponding Plugin System Events...

            However, I am still getting taken to my 404 page.

            (I even disabled SEO Strict URL plugin...)

            Hmmm...I will have to perform some troubleshooting to see what is/isn’t getting executed...

            NOTES:
            - I am using friendly alias paths, but you appear to account for that
              Mike Reid - www.pixelchutes.com
              MODx Ambassador / Contributor
              [Module] MultiMedia Manager / [Module] SiteSearch / [Snippet] DocPassword / [Plugin] EditArea / We support FoxyCart
              ________________________________
              Where every pixel matters.
              • 7205
              • 9 Posts
              OpenGeek:

              Thanks for your help. I’m going to give the plugin a shot. Which system events should I have checked for this plugin? Thanks!

              Nevermind that! I’m so stupid... Ok, so I’ve checked the OnWebPageInit and OnPageNotFound system events but still no dice. Is there anything else I should try? Thanks again.

              Devin
                • 23491 ☆ A M B ☆
                • 1,056 Posts
                Quote from: OpenGeek at Aug 24, 2007, 05:48 PM

                just check the OnWebPageInit and OnPageNotFound events.
                  Mike Reid - www.pixelchutes.com
                  MODx Ambassador / Contributor
                  [Module] MultiMedia Manager / [Module] SiteSearch / [Snippet] DocPassword / [Plugin] EditArea / We support FoxyCart
                  ________________________________
                  Where every pixel matters.
                  • 7205
                  • 9 Posts
                  Oh, and the reason I was getting the redirect error was because I hadn’t setup an error page for 404s. Now I get sent to my 404 page.
                    • 22303 MODX Staff
                    • 10,725 Posts
                    I’ve tested both with and without use_alias_paths here locally and seem to be having no problem getting it to work as I expect. I’ve also tried it with and without a friendly URL suffix. Do either of you have additional plugins attached to either of those events? If so, try re-sorting them so this one comes first in the execution order.
                      • 7205
                      • 9 Posts
                      OpenGeek,

                      I don’t have any other plugins configured for those two system events. And I’m not using a prefix or suffix for friendly URLs.