We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 21257 MODX Staff
    • 730 Posts

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


    I just made a semantic change to the query string.. the string you’re looking for will now be passed in the GET string as "offer_string". Hope this one works. It still looks for a trailing slash, but that trailing slash won’t be passed in the query string.
      Mike Schell
      Lead Developer, MODX Cloud
      Email: [email protected]
      GitHub: https://github.com/netProphET/
      Twitter: @mkschell
      • 32645
      • 377 Posts
      I’ve decided to cut the part after the /offer/ to just the first part just to make this thing easier, also the first part happens to be unique - so it should not cause major problems.

      IE: /offer/MBJ7042C/

      I’ve put a "Hello world" on the `offer` page just in case it was causing a problem.

      I tried your code but I still get 404 errors. I tried commenting and uncommenting the Options +FollowSymlinks part, but this made no effect.

      Its a shame there was never a debug with RegEx, then I could see what’s going wrong and where...

      Options +FollowSymlinks
      RewriteEngine On
      RewriteBase /
      
      RewriteRule ^offer/(.*)/$ index.php?q=offer&offer_string=$1 [L,QSA]
      
      # The MODx Friendly URLs part
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
      


        • 21257 MODX Staff
        • 730 Posts
        Does your offer page itself still have an alias of just "offer"? Is it in a container?
          Mike Schell
          Lead Developer, MODX Cloud
          Email: [email protected]
          GitHub: https://github.com/netProphET/
          Twitter: @mkschell
          • 32645
          • 377 Posts

          Does your offer page itself still have an alias of just "offer"? Is it in a container?

          The offer page itself has a page alias of `offer`

          Is it in a container? Yes, it is.

          It sits inside a container called `latest-offers`, but ideally I’d like the regex to work regardless of where it is in the document root/path.

          So, the full path would be:


          http://modx.localhost/latest-offers/offer/MBJ7042C

          I hope this helps.
            • 21257 MODX Staff
            • 730 Posts
            The friendly URLs part of MODx works by analyzing what’s passed in the query string for known document aliases.
            So the rewrite rules pass the alias, not a document id, to tell modx what document the user wants.
            As far as I know, you have to pass the alias to the parser. I don’t know of a way to pass the document id.
            So below, the q= parameter has to be your script’s full alias. That’s why it’s not working.
            RewriteRule ^offer/(.*)/$ index.php?q=containerx/offer&offer_string=$1 [L,QSA]
            

              Mike Schell
              Lead Developer, MODX Cloud
              Email: [email protected]
              GitHub: https://github.com/netProphET/
              Twitter: @mkschell
              • 21257 MODX Staff
              • 730 Posts
              Actually, come to think of it, I was wrong about not being able to pass the doc id. Doh!
              You should be able to pass it in place of the alias. Unless you’ve got the SEO Strict URLs plugin (or similar) going, then MODx should behave as you are hoping.
              RewriteRule ^offer/(.*)/$ index.php?q=123&offer_string=$1 [L,QSA]
              

                Mike Schell
                Lead Developer, MODX Cloud
                Email: [email protected]
                GitHub: https://github.com/netProphET/
                Twitter: @mkschell
                • 32645
                • 377 Posts
                I tried this;

                RewriteRule ^offer/(.*)/$ index.php?q=latest-offers/offer&offer_string=$1 [L,QSA]

                It however, unfortunately does not work. Perhaps there’s another solution.
                  • 21257 MODX Staff
                  • 730 Posts
                  undecided I think I need to stop giving out mod_rewrite advice without access to develop and test the rules myself.. it’s always a bit of trial and error, and a forum is no place for a debugging process.
                  Sorry to lead you astray.
                    Mike Schell
                    Lead Developer, MODX Cloud
                    Email: [email protected]
                    GitHub: https://github.com/netProphET/
                    Twitter: @mkschell
                    • 32645
                    • 377 Posts
                    Its quite okay, I’ll hopefully get there in the end!
                    :)


                    I’ve had to roll it back to this, and just to clarify I’m after the offer_id part.
                    /latest-offers/offer/?offer_id=ANU606C
                      • 32645
                      • 377 Posts
                      Hi,

                      For the URL pattern, as I couldn’t get Regular Expressions to work, so I’ve hacked a solution that is reliant upon the 404 page, called a 404 Router and takes it idea from the Friendly URLS on the Fly post at: http://modxcms.com/forums/index.php/topic,33293.15.html

                      Basically what happens is, you go to:

                      /latest-offers/offer/MBJ7042C

                      This goes to the 404 error page, I check for the occurance of the "offer" part -- if its there, I redirect to the single offers page with the 4th element of the URL pattern (MBJ7042C) and use this to find the relevant holiday offer.

                      Naturally, I’d love to have a regular expression solution, but everything I’ve tried seems to fail.

                      Thanks