We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 22680
    • 2 Posts
    I just started using MODx Evo 1.0 on a new project and absolutely love it so far. I come from an EE background and the way MODx works makes so much more sense to me. I’ve run into two small issues I haven’t been able to solve so I’d like some help.

    1. Can document the alias in a friendly URL be made to work case-insensitive? I want www.example.com/MyBook and www.example.com/mybook to go to the same document. I added the "NC" flag to the htaccess file as noted in the documentation and this didn’t help (using Apache 2 with mod_rewrite/PHP5, etc). Friendly URLs are otherwise working perfectly. Any other suggestions?

    2. I created a manager role which allows the user to edit and save documents, but not create or delete. However, it seems they can still duplicate an existing document and therefore are able to make new pages. Is there a way to disable duplicating permissions?

    Thanks!
      • 26931
      • 2,314 Posts
      Hi there,

      Can document the alias in a friendly URL be made to work case-insensitive?
      somewhere in on the forum i once found this plugin (can’t find the thread anymore...):

      create a new plugin with the following code:
      $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();
      }
      }
      }

      check SytemEvents "OnWebPageInit" and "OnPageNotFound"
      j
        • 27516
        • 13 Posts
        I needed to add the explode() call to work with a URL suffix (www.example.com/MyBook.html or www.example.com/mybook.html):

        $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) {
          $aliasParts = explode(".", $alias);
          $aroot = $aliasParts[0];   // drop URL suffix
          if (!isset($modx->documentListing[$aroot])) {
            $documentListingNC = array_change_key_case($modx->documentListing);
            if (isset($documentListingNC[strtolower($aroot)])) {
              $actualDocId= $documentListingNC[strtolower($aroot)];
              $modx->sendRedirect($modx->makeUrl($actualDocId), 0, '', 'HTTP/1.0 301 Moved Permanently');
              exit();
            }
          }
        }
        
          • 10226
          • 412 Posts
          I’m not really following the whole line of duplicate permissions, but this solved one problem I had.

          The other issue is that I need a way for the aliases to be stored without converting all to lowercase.

          If I call the page alias cRazYpaGE - it is stored as ’crazypage’ and all my links are lowercase. I assume wayfinder has nothing to do with it. Looks like they are converted to lc before they go in the database. This should be a fairly easy hack, pobably to the core, but I have no idea where to look.

          Thanks!
            • 26931
            • 2,314 Posts
            If I call the page alias cRazYpaGE - it is stored as ’crazypage’ and all my links are lowercase. I assume wayfinder has nothing to do with it. Looks like they are converted to lc before they go in the database. This should be a fairly easy hack, pobably to the core, but I have no idea where to look.
            check your TransAlias Plugin settings
              • 5699
              • 46 Posts
              computersolutions.cn Reply #6, 16 years, 3 months ago
              Note that the code for suffix fix breaks if URL’s have embedded .’s in.

              eg

              /SomEuRL_is_Ok works

              but

              /SomE.uRl_is_oK would break.

              Suggest change the
              $aliasParts = explode(".", $alias);
              $aroot = $aliasParts[0];   // drop URL suffix
              
              

              To

              if ($modx->config['friendly_url_suffix'] ){ //Are suffixes on?
                  $aliasParts = explode(".", $alias);  //Yes, split into parts based on . delimiter
              $aroot ='';
              $acount = count($aliasParts);
              $suffix=".";$i=0;
                  while ($i<$acount) { //Drop the last .xxx
                  if ($i == $acount-1) $suffix="";
                  $aroot.= $aliasParts[$i] . $suffix;
              $i++;
                  }
              
              }
              else {
                //No Suffix to remove
                $aroot = $alias;   
              } 






              The complete updated code is below:

              $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 ($modx->config['friendly_url_suffix'] ){ //Are suffixes on?
                  $aliasParts = explode(".", $alias);  //Yes, split into parts based on . delimiter
                  $aroot ='';$acount = count($aliasParts);$suffix=".";$i=0;
                  while ($i<$acount) { //Drop the last .xxx
                  if ($i == $acount-1) $suffix="";  //While i could do a substr post loop.  this is actually faster 
                  $aroot.= $aliasParts[$i] . $suffix;
                  $i++;
                  }
              
              }
              else {
                //No Suffix to remove
                $aroot = $alias;   
              } 
              
                if (!isset($modx->documentListing[$aroot])) {
                  $documentListingNC = array_change_key_case($modx->documentListing);
                  if (isset($documentListingNC[strtolower($aroot)])) {
                    $actualDocId= $documentListingNC[strtolower($aroot)];
                    $modx->sendRedirect($modx->makeUrl($actualDocId), 0, '', 'HTTP/1.0 301 Moved Permanently');
                    exit();
                  }
                }
              }
                • 36533
                • 65 Posts
                So, I've tried this, but for some reason newly generated pages aren't working.. however, if I go to edit the page and simply save it, the page pops in.

                When I save, it still rewrites the alias to all lower case, but works regardless of the case I use in the URL.

                I am also using another plugin which generates the pages automatically for new users. Is there perhaps a glitch happening with that?

                Here is my GenerateUserPage Plugin:

                if($mode=="new"){   
                    $wuid = $username;
                    $table_name = $modx->getFullTableName( 'site_content' );
                    $fields = array(
                                        'type'  =>  'document',
                            'contentType'   => 'text/html',
                            'pagetitle' => $wuid,
                            'alias'     => $wuid,
                            'published' => '1', //is the page published?
                            'parent'    => '16', //what is the parent of this new page?
                            'isfolder'  => '0', // lets make this a folder
                            'template'  => '15', //type template id here
                            'cacheable' => '0',
                            'createdby' => $wuid,
                            'createdon' => time(),
                            'editedon'  => time(),
                            'publishedon'   => time(),
                            'hidemenu'  => '1'
                            );
                
                    $modx->db->insert( $fields, $table_name); // put the fields in the db (id wil be created incremental.)
                 
                //Create  placeholder and put the id in a session to use for mail or whatever.
                $_SESSION['eigenpaginaid'] =  $modx->db->getInsertId();
                $modx->setPlaceholder('eigenpaginaid', $modx->db->getInsertId());
                 
                   return;
                }


                With event "OnWebSaveUser" checked.

                Here is my AliasCase Plugin:

                $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 ($modx->config['friendly_url_suffix'] ){ //Are suffixes on?
                    $aliasParts = explode(".", $alias);  //Yes, split into parts based on . delimiter
                    $aroot ='';$acount = count($aliasParts);$suffix=".";$i=0;
                    while ($i<$acount) { //Drop the last .xxx
                    if ($i == $acount-1) $suffix="";  //While i could do a substr post loop.  this is actually faster 
                    $aroot.= $aliasParts[$i] . $suffix;
                    $i++;
                    }
                 
                }
                else {
                  //No Suffix to remove
                  $aroot = $alias;   
                } 
                 
                  if (!isset($modx->documentListing[$aroot])) {
                    $documentListingNC = array_change_key_case($modx->documentListing);
                    if (isset($documentListingNC[strtolower($aroot)])) {
                      $actualDocId= $documentListingNC[strtolower($aroot)];
                      $modx->sendRedirect($modx->makeUrl($actualDocId), 0, '', 'HTTP/1.0 301 Moved Permanently');
                      exit();
                    }
                  }
                }


                With events "OnWebPageInit" and "OnPageNotFound" checked

                Also, if I preview the page before doing an edit/save.. friendly URL breaks and I get the pageid+.php

                Any ideas? [ed. note: nuwebstudios last edited this post 14 years, 11 months ago.]