We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 27072
    • 76 Posts
    Hello all.

    I have thousands of celebrities and a a few published pages for each one.

    For example:
    Celebrity: Albert Einstein
    Page: Numerology Profile

    The desired URL for this page would be: .../albert-einstein/numerology-profile.html

    I have already performed the following actions:

    • Created a document for numerology profiles, with a Document’s alias: numerology-profile.html
    • The snippet that is called from the document templates retrieves the unique value albert-einstein from the URL, and updates a placeholder [+URLprefix+] with the value albert-einstein.
    • Placeholder [+URLprefix+] is placed in site’s Prefix for friendly URLs.

    Now, all MODx/WayFinder/Breadcrumbs’s and other navigation scripts parse the desired URL: .../albert-einstein/numerology-profile.html

    But the problem is that this page is not accessible and the system will issue a 404 instead.

    I can think of three possible methods to make this FURL accessible:

    • Include a snippet in the 404 page that performs a server.transfer to .../numerology-profile.html?FileName=albert-einstein
    • Set a rewrite rule in .htaccess - which I have no clue what to set or how to write it.
    • Make a wiser use of site and/or document settings in order to accomplish system recognition of the friendly URL.

    Your advice is greatly appreciated. Thanks.
      Cheers,
      Shlomo Tommer
      • 9207 ☆ A M B ☆
      • 2,475 Posts
      What you describe might normally be done by structuring the URLs the other way around, e.g.
      numerology-profile/albert-einstein.html

      I don’t think you can play with the "alias" in the way that you are... that’s just a feeling I have. Sure, WayFinder and other Snippets can read that value from the database and display it, because they’re not actually doing anything with it. When a page request comes in to a site, though, I don’t think Apache has time to play around with the URL. I think MODx does a quick and dirty lookup to find the relevant page to load. How many pages have you tried using the [+URLprefix+] on? Aren’t you running into restrictions on unique aliases?

      What would be more common in MODx would be that you create a page with an alias of "albert-einstein", and then create a another page under that page with a "numerology-profile" alias. But that architecture may be totally redundant.

      Can you verify that friendly URLs are working on "normal" pages on your site?

      Another way to do this might be to put PHP code at a page above the people. e.g. if you had www.yoursite.com/people/albert-einstein/numerology-profile.html, then you could put a Snippet in the "people" page that would grab URL segments. That’s how some other CMS’s do it (e.g. Expression Engine).

      The one last thought I have is that you put the existing code you wrote to parse your [+URLprefix+] placeholder into a Plugin (not just a Snippet). The reason is because a Snippet executes when a page loads, and you don’t have a choice when in the loading the Snippet executes... it will always be at the same time... and it may be too late for what you are trying to do. If you make a Plugin, however, you can set the Plugin to execute at an event earlier in the loading sequence.

      Hope that makes sense.
        • 27072
        • 76 Posts
        Quote from: Everett at Feb 22, 2009, 10:14 PM
        What you describe might normally be done by structuring the URLs the other way around, e.g.
        numerology-profile/albert-einstein.html
        I see your point and it would obviously make life so much easier, but there are two reservations, the main one being SE consideration -> building a common theme around Albert Einstein vs. around Numerology. Hence, in the eyes of search engines, the parent "folder" must be that of the celebrity name.

        Quote from: Everett at Feb 22, 2009, 10:14 PM
        I don’t think you can play with the "alias" in the way that you are... that’s just a feeling I have.  Sure, WayFinder and other Snippets can read that value from the database and display it, because they’re not actually doing anything with it.  When a page request comes in to a site, though, I don’t think Apache has time to play around with the URL.  I think MODx does a quick and dirty lookup to find the relevant page to load.
        That concurs with the findings of my tests. I just wanted to make sure that I haven’t missed anything as a newbie.

        Quote from: Everett at Feb 22, 2009, 10:14 PM
        How many pages have you tried using the [+URLprefix+] on?  Aren’t you running into restrictions on unique aliases?
        Just tried a few and didn’t run into any non-unique alert, even though I have selected this option in site FURL settings.

        Quote from: Everett at Feb 22, 2009, 10:14 PM
        What would be more common in MODx would be that you create a page with an alias of "albert-einstein", and then create a another page under that page with a "numerology-profile" alias.  But that architecture may be totally redundant.
        Inconceivable with 115K and more celebrities.

        Quote from: Everett at Feb 22, 2009, 10:14 PM
        Can you verify that friendly URLs are working on "normal" pages on your site?
        No problems whatsoever.

        Quote from: Everett at Feb 22, 2009, 10:14 PM
        Another way to do this might be to put PHP code at a page above the people.  e.g. if you had www.yoursite.com/people/albert-einstein/numerology-profile.html, then you could put a Snippet in the "people" page that would grab URL segments.  That’s how some other CMS’s do it (e.g. Expression Engine).
        What a fantastic idea. Thanks a bunch. What you actually suggest is to substitute htaccess rules or 404 page script with a snippet that will Server.Transfer calls from the people document to index.php?id=<case by calling URL>&FileName=<extracted from URL>. Seems like a great way to preserve business logic within the MODx application, without depending on external files and platforms (such as IIS with no ISAPI_Rewrite).

        Quote from: Everett at Feb 22, 2009, 10:14 PM
        The one last thought I have is that you put the existing code you wrote to parse your [+URLprefix+] placeholder into a Plugin (not just a Snippet).  The reason is because a Snippet executes when a page loads, and you don’t have a choice when in the loading the Snippet executes... it will always be at the same time... and it may be too late for what you are trying to do.  If you make a Plugin, however, you can set the Plugin to execute at an event earlier in the loading sequence.
        I haven’t got my hands dirty with plugins yet. Thanks for the tip. Luckily - all template and document parsing are working flawlessly as is because the function $modx->setPlaceholder() forces the script to interpret such values prior to the rendering phase.

        Thank you so much for your investment in my guidance. Be blessed.
          Cheers,
          Shlomo Tommer
          • 3749
          • 24,544 Posts
          I’m not sure I’m following this completely, but if you are using a snippet and the snippet knows the id of the page you want, you could use:

          $url  = $modx->makeURL($id);
          $modx->sendRedirect($url);


          and MODx will work out the details and send the user directly to the page.
            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
            • 27072
            • 76 Posts
            Quote from: BobRay at Feb 23, 2009, 02:30 AM

            I’m not sure I’m following this completely, but if you are using a snippet and the snippet knows the id of the page you want, you could use:

            $url  = $modx->makeURL($id);
            $modx->sendRedirect($url);


            and MODx will work out the details and send the user directly to the page.

            Thank you so much for unraveling this API call for me.

            sendRedirect() won’t do the trick because it actually use HEADER(LOCATION) derivative, so the browser actually moves to the new URL.

            However, http://wiki.modxcms.com/index.php/API:sendForward"" target="_blank" rel="nofollow">MODx wiki explains another function - $modx->sendForward($DocID) which is as good as ASP’s Server.Transfer - the browser stays on the originally requested URL while the server-side page request changes to the real one.

            This function makes SEO life real easy provided that I’ll be able to pass another query parameter with this function: celebrity identity.

            Thanks again for a bulls eye.
              Cheers,
              Shlomo Tommer
              • 3749
              • 24,544 Posts
              I should have thought of that.  wink

              Note that unlike $modx->sendRedirect(),  $modx->sendForward() takes the id of the page, not the URL so you don’t need makeURL(). smiley

              Note also that if the page you’re forwarding to has snippets that include files with relative paths, they may not be found.
                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
                • 29774
                • 386 Posts
                No tested but this rewrite rule should work:

                RewriteRule ^([^/]*)(/)?$/numerology-profile/ /numerology-profile/?FileName=$1 [nc]
                


                /albert-einstein/numerology-profile/

                to

                /numerology-profile/?FileName=albert-einstein

                I’ve left off the suffix .html, not sure why people bother with that when a trailing slash is all you need.
                  Snippets: GoogleMap | FileDetails | Related Plugin: SSL
                  • 27072
                  • 76 Posts
                  Quote from: therebechips at Feb 23, 2009, 04:29 AM

                  RewriteRule ^([^/]*)(/)?$/numerology-profile/ /numerology-profile/?FileName=$1 [nc]
                  

                  /albert-einstein/numerology-profile/ to /numerology-profile/?FileName=albert-einstein

                  After spending hours (successfully) on URL fragmentation via snipped called from the 404 page, I tend to agree that your method is the best route, i.e. setting a rule for each document.

                  However, the rule doesn’t work for me and I never managed to take even baby steps in htaccess scripting.
                  Can you help me debug your code please?

                  Document’s alias stores: birth-data ([glow=red,2,300]MODx won’t allow a trailing slash here[/glow])

                  Tools->Configuration->Friendly URLs->

                  • Prefix for friendly URLs: [+FileName+]/
                  • Suffix for friendly URLs: /

                  Result of URL parsing: http://foo.com/britney-spears/birth-data/

                  I set your rule at the bottom of the .htaccess file as follows:
                  RewriteRule ^([^/]*)(/)?$/birth-data/ /birth-data/?FileName=$1 [nc]


                  Many thanks for your efforts and support.
                    Cheers,
                    Shlomo Tommer
                    • 29774
                    • 386 Posts
                    You would need to make it the first rule after the rewrite engine is initialised, otherwise the 404 handling will intercept it first.


                    Tools->Configuration->Friendly URLs->
                    * Prefix for friendly URLs: [+FileName+]/
                    * Suffix for friendly URLs: /

                    I’d never thought of doing that - how clever smiley
                      Snippets: GoogleMap | FileDetails | Related Plugin: SSL
                      • 32645
                      • 377 Posts
                      I’ve got a similar problem and I’m not sure how to solve it, and after reading this topic I’m a little closer -- but I am still having issues as to how to solve it.

                      My situation
                      ----------
                      A travel website where you click on an offer and it takes you to that offer page.
                      The offers are not in MODX (there’s over 500,000 of them) and I’m wanting to use a friendly URL to grab the related offer ID, and then spit it into a template.


                      Another way to do this might be to put PHP code at a page above the people. e.g. if you had www.yoursite.com/people/albert-einstein/numerology-profile.html, then you could put a Snippet in the "people" page that would grab URL segments. That’s how some other CMS’s do it (e.g. Expression Engine).

                      How do you grab URL segments with MODX? Is there an easy way to do this?

                      Here’s what I’d like it to be:
                      www.yoursite.com/holidays/offer/id/

                      Where ID is a number, or a page alias. I want to grab the ID/page alias and then use this to do a search in the DB.

                      Also, on this page:

                      http://wiki.modxcms.com/index.php/DB_query_and_Placeholders

                      It describes how you can create a page to do a DB query and then spit out the contents into a placeholder. This is what I intend to use for the holiday offer page, in fact I have already got this working later on where I’m displaying the last 10 holiday offers.

                      I’ve heard that you can put in a placeholder inside the page title and you can use it.

                      I’ve tried this, but I can never seem to grab the placeholder though that I’ve entered in the page title.

                      For example, can I create a structure like this:


                      // Manager tree view
                      Holidays (container)
                      -> Offers (container)
                      --->[+id+] (page)

                      And MODX will implicantly know how to handle the placeholder?

                      Can someone confirm how you use Placeholders inside page titles and use them?

                      Thanks