We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
  • You can easily provide custom URLs in two ways in Evolution:

    1. Using a snippet that makes use of the sendForward() method:
    <?php
    $id = !empty($id) ? (integer) $id : 0;
    if ($id > 0) {
        $modx->sendForward($id);
    }
    return '';
    ?>
    which would be called from a Resource in the correct location of the Tree to build the URL you want. This will simply present the Resource represented by the $id parameter under the URL of the Resource it is called from.

    2. If you can logically find the real Resource based on a URI pattern (for example), you can create a plugin that is registered to the OnPageNotFound event that looks at the $_SERVER[’REQUEST_URI’] and uses sendForward() to serve the real Resource from your custom scheme. Here is a minimal example:
    <?php
    // Get the REQUEST_URI and get rid of the first and last slash
    // e.g. /foo/bar/ becomes foo/bar
    $requestURI = trim(strtolower($_SERVER['REQUEST_URI']), '/');
    
    // Explode the elements of the requestURI so you can inspect each segment
    $requestParts = explode('/', $requestURI);
    
    // Check the first element of the URI for a specific value (as an example)
    if ($requestParts[0] == 'foo') {
        // Additional logic for matching your custom URLs
        $match = 0;
        if ($requestParts[1] == 'bar') {
            // if the second segment of the URI is 'bar', match Resource with id 20
            $match = 20;
        }
        
        // Once you identify a match, just sendForward
        if (!empty($match)) {
            $modx->sendForward($match);
        }
    }
    ?>
      • 4471
      • 3 Posts
      Hi,

      I’m trying to implement these solutions but it seems that I could use a few more details.

      I use MLX multilanguage add-on and I want to hide the first folder in the URL, corresponding to the language container. I want www.example.com/en/page.html to be available as www.example.com/page.html . I only want this for the main language.

      Is this possible?


      Thank you.
        • 32982
        • 674 Posts
        You can hide from HTACCES (burt you nieed to modifie menu snippets)
        putting this

        RewriteRule ^(----dirToHide-------)/(.*)$ $1 [L,QSA]
        RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

        instead this

        RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

        hi
          Jabiertxof (formerly XYZVISUAL)
          My bussines: http://marker.es
          https://www.youtube.com/user/jabiertxof/videos
          • 26931
          • 2,314 Posts
          I use MLX multilanguage add-on and I want to hide the first folder in the URL, corresponding to the language container. I want www.example.com/en/page.html to be available as www.example.com/page.html . I only want this for the main language.
          would something like this possible with OpenGeeks plugin code from above, or with htaccess ... can someone maybe provide an example code smiley // xyzvisual’s htaccess solution didn’t work for me

          thanks, j
            • 7557
            • 61 Posts
            Hi.
            I find the solution for Revolution. Not nice, but worked for me. It is a little modification of core code. After a day of testing I did not notice the problems, but does not mean that they are not possible.
            I changed this file:
            core\model\modx\modcachemanager.class.php
            Revo v2.04 pl2.
            Line 79
            From this:
            $resourceFields= 'id,parent,alias,isfolder,content_type';

            to
            $resourceFields= 'id,parent,alias,isfolder,content_type,hidemenu';

            And
            Line 135:
            $parentResources[]= "{$parentAlias}";

            to:
            if($currResource->hidemenu == 0) $parentResources[]= "{$parentAlias}";


            You must clear cache to see changes.
              • 14317
              • 3 Posts
              DJ... you’re my hero!

              Quote from: dj13 at Nov 04, 2010, 12:49 AM

              Hi.
              I find the solution for Revolution. Not nice, but worked for me. It is a little modification of core code. After a day of testing I did not notice the problems, but does not mean that they are not possible.
              I changed this file:
              core\model\modx\modcachemanager.class.php
              Revo v2.04 pl2.
              Line 79
              From this:
              $resourceFields= 'id,parent,alias,isfolder,content_type';

              to
              $resourceFields= 'id,parent,alias,isfolder,content_type,hidemenu';

              And
              Line 135:
              $parentResources[]= "{$parentAlias}";

              to:
              if($currResource->hidemenu == 0) $parentResources[]= "{$parentAlias}";


              You must clear cache to see changes.
                • 26921
                • 4 Posts
                Hello experts,
                Thanks for reading.I am newbie and need your help.
                So here i dont want the hidden folder, i want any folder(may be subfolder, read below u will get it).
                _______________________________________

                I have a link like http://syd-srv06.ezyreg.com/~haha7316/personal/personal/CV/
                I want to make it like http://syd-srv06.ezyreg.com/~haha7316/personal/CV/
                remove /personal/ fully from the link.
                some more links :
                Currently : http://syd-srv06.ezyreg.com/~haha7316/lumina-diem/Case-History/Section-1/
                I want it : http://syd-srv06.ezyreg.com/~haha7316/lumina-diem/Case-History-Section-1/
                replace / with -

                Currently : http://syd-srv06.ezyreg.com/~haha7316/lumina-diem/Transcripts/Transcripts-Section-5-Temporary-Orders-Hearing/
                i want it : http://syd-srv06.ezyreg.com/~haha7316/lumina-diem/Transcripts-Section-5-Temporary-Orders-Hearing/
                remove /Transcripts/ fully from the link.
                --------
                Note: /personal/personal/ here both are weblinks,parent weblink : personal->personal(child weblink)->CV(Document)
                Its nice to organise the documents in this way but i am using furl with path enabled so now some child weblinks(contailers) are badly needed to removed from the full URL.
                ---------

                How can i do it using .htaccess ?

                My current .htaccess is like followings :
                __________________________
                # For full documentation and other suggested options, please see
                # http://svn.modxcms.com/docs/display/MODx096/Friendly+URL+Solutions
                # including for unexpected logouts in multi-server/cloud environments

                Options +FollowSymlinks
                RewriteEngine on
                RewriteBase /~haha7316/

                # Fix Apache internal dummy connections from breaking [(site_url)] cache
                RewriteCond %{HTTP_USER_AGENT} ^.*internal\ dummy\ connection.*$ [NC]
                RewriteRule .* - [F,L]

                # Rewrite domain.com -> www.domain.com -- used with SEO Strict URLs plugin
                #RewriteCond %{HTTP_HOST} .
                #RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
                #RewriteRule (.*) http://www.example.com/$1 [R=301,L]

                # Exclude /assets and /manager directories from rewrite rules
                RewriteRule ^(manager|assets) - [L]

                # For Friendly URLs
                RewriteCond %{REQUEST_FILENAME} !-f
                RewriteCond %{REQUEST_FILENAME} !-d
                RewriteRule ^(.*)$ index.php?q=$1 [L,QSA,NC]

                # Reduce server overhead by enabling output compression if supported.
                #php_flag zlib.output_compression On
                #php_value zlib.output_compression_level 5


                RewriteCond %{HTTP_HOST} ^courtofpublicjustice.com$ [OR]
                RewriteCond %{HTTP_HOST} ^www.courtofpublicjustice.com$
                RewriteRule ^/?$ "index\.php\?id\=142" [R=301,L]

                RewriteCond %{HTTP_HOST} ^luminadiem.com$ [OR]
                RewriteCond %{HTTP_HOST} ^www.luminadiem.com$
                RewriteRule ^/?$ "index\.php\?id\=17" [R=301,L]
                _______________________________________ __________
                  • 34361
                  • 2 Posts
                  Appreciate the info, it&rsquo;s good to know.
                    • 19328
                    • 433 Posts
                    I would like to hide certain hidden folders from the friendly alias path as well (and switching off friendly alias path is not an option). However, the core modification DJ suggested can't be applied anymore, seems like the code has slightly changed.

                    I thought I could also hide certain folders from the URL by creating RewriteRules. But I can't get it to work (I'm not an expert on rewriterules).

                    Anyone got an idea what I should add before (or after) the Friendly URLs part of MODX to hide the container named 'SERVICE'?

                    # The Friendly URLs part
                    RewriteCond %{REQUEST_FILENAME} !-f
                    RewriteCond %{REQUEST_FILENAME} !-d
                    RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]


                    I don't know if this is even possible, because it would be a rewriterule that is applied after the friendly alias path is created...

                    hope someone can help!
                      • 37582
                      • 65 Posts
                      Hey michelle,

                      is it just a single folder you want to hide, i.e. where your modx installation resides?

                      I solved this problem by merely altering your furls part to this:

                      # The Friendly URLs part
                      RewriteCond %{REQUEST_FILENAME} !-f
                      RewriteCond %{REQUEST_FILENAME} !-d
                      RewriteRule ^(.*)$ cms/index.php?q=$1 [L,QSA]


                      While cms is my modx installation folder. Then, you also have to alter your config.inc.php and your contexts site_url setting and your relative paths to css files, images etc.

                      If you set your configuration to show full paths as /container/alias.html and only want to hide certain containers, youmight want to go with a different solution. A quick solution would be to just take every single url and rewrite it:

                      RewriteRule ^file.html$ path-to-your/file.html


                      or more generally

                      RewriteRule ^(.*)$ path-to-your/$1 [L,QSA]


                      While I am not sure whether the second example is syntactically correct and works right away...