We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 17544
    • 86 Posts
    If I have an alias with upper case letters, say "myNewPage", it will return 404.

    After looking into the core code on line 1023 document.parser.class.inc.php

    $this->documentIdentifier = $this->documentListing[$this->documentIdentifier];


    This is where conversion from alias to ID happened. However, $this->documentListing is using original "myNewPage" as the key while documentIdentifier at this point is all lowercased - mynewpage. So it coundn’t find a match and return 404. Since $this->documentListing["myNewPage"] is not $this->documentListing["mynewpage"].

    I try to debug further and notice that $_REQUEST[’q’] (which is used to generate $this->documentIdentifier) is already in lowercase early on. $_REQUEST[’q’] was passed to index.php via .htaccess. So do you have any clue why .htaccess would pass the lowercased version instead of the original version?

    Using Apache/1.3.37 (Win32) PHP/5.1.6 and original .htaccess supply in installation files.

    # Rewrite directives here for SEF (Search Engine Friendly) URLs
    
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    
    # If your MODx installation is in a subdirectory, change the following line to match the physical
    # path to the "root" of the site as follows:
    # RewriteRule ^(.*)$ /path/to/subdirectory/index.php?q=$1 [L,QSA]
    
    RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
    


    Update:

    I tried it on my Unix hosting account and it works very well. So I think it is either my system problem or Windows platform problem.





      • 22815
      • 1,097 Posts
      Interesting. As you probably know, Windows’ file system treats MyPage.html and mypage.html as the same thing.

      I’ve never actually tried using mixed-case aliases, because I am used to keeping things lower case. Also for search engine purposes, it is thought to be better to use my-new-page.html

      I have previously thought that it may well be better if MODx had a routine that first looked for an exact match, and then looked for a differently-cased version that it could redirect to - but if certain setups screw up the casing, that would seem to result in an infinite loop. Hmmn.
        No, I don't know what OpenGeek's saying half the time either.
        MODx Documentation: The Wiki | My Wiki contributions | Main MODx Documentation
        Forum: Where to post threads about add-ons | Forum Rules
        Like MODx? donate (and/or share your resources)
        Like me? See my Amazon wishlist
        MODx "Most Promising CMS" - so appropriate!
        • 17544
        • 86 Posts
        Found the bug report here
        http://modxcms.com/bugs/task/196?histring=friendly%20url&tasks=last

        But this report doesn’t mention that it is related to Windows.

          • 17544
          • 86 Posts
          I did a quick hack on the core file document.parser.class.inc.php.

          replacing (line around 1020)

          $this->documentIdentifier = $this->documentListing[$this->documentIdentifier];
          


          with

                	if (key_exists($this->documentIdentifier, $this->documentListing))
                  	$this->documentIdentifier = $this->documentListing[$this->documentIdentifier];
                  else {
                  	$lowerCaseDocumentListing = array();
                  	foreach ($this->documentListing as $key=>$value)  		
                  		$lowerCaseDocumentListing[strtolower($key)] = $value;
                  	$this->documentIdentifier = $lowerCaseDocumentListing[$this->documentIdentifier];
                  }
          


          It creates a temporay documentListing with all keys lowercased to do the match.
            • 22303 MODX Staff
            • 10,725 Posts
            A better approach from my perspective is to just change the rewrite rule to ignore case...

            RewriteRule ^(.*)$ index.php?q=$1 [L,QSA,NC]
              • 17544
              • 86 Posts
              The NC won’t affect anything here as there are no comparison but just ’passing’. The windows system is sending the file name in lowercase. That’s what $_REQUEST[’q’] is assigned to.


              ’nocase|NC’ (no case)
              This makes the test case-insensitive, i.e., there is no difference between ’A-Z’ and ’a-z’ both in the expanded TestString and the CondPattern. This flag is effective only for comparisons between TestString and CondPattern. It has no effect on filesystem and subrequest checks.
                • 22303 MODX Staff
                • 10,725 Posts
                In my perspective, this is a cross-platform system, and best practices dictate that alias’ should be all lowercase in the system, since Windows is case-insensitive. The NC in the rewrite rule ensures that links that are not all lowercase, get resolved to the proper lowercase variation. This seems the only sane solution to me, and trying to differentiate between MyPage.html and mypage.html seems not only contrary to those best practices, but also can make accessibility to your site a little less intuitive. But that’s just my opinion.

                On the other hand, I don’t see why this couldn’t easily be worked around using a plugin though...
                  • 17544
                  • 86 Posts
                  haha. Not a big deal for me because windows is my ’test bed’ area and Unix is my real website.

                  The reason I have to keep the UpperCase file names is because I am importing my site to it and thus require me to keep the old file name system (which uses upper case) so I won’t affect my search engine listing.

                  If a plugin is to be implemented, what I can think of is OnWebPageInit event, modify $this->documentListing array to include all lowercased keys in them as well.
                    • 17544
                    • 86 Posts
                    Ops, just try it out but OnWebPageInit event invoke too late so I can’t make changes to $this->documentListing in time. Can’t find another event that fired earlier. Maybe can use a snippet but need to put the snippent on the template.

                    Just hack the core at the moment. laugh
                      • 28580
                      • 24 Posts
                      So if I understand correctly forcing all aliases to lowercase is intended behavior?

                      This has caused a problem for us when upgrading from 0.9.6.2 which allowed mixed case to 1.0.4 which does not. The aliases were preserved during the upgrade but if that page is edited subsequently the alias is converted to lowercase. Although I have added NC to the rewrite rules for certain specific pages the general case of RewriteRule ^(.*)$ index.php?q=$1 [L,QSA,NC] does not solve this problem. As a further consideration with 5000+ pages and multiple editors I cannot guarantee that there have not been pages created whose aliases differ only by case.

                      Is there any way to allow case to be preserved in the alias path?