We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 13993
    • 100 Posts
    OK I have been trying to test every event process I could think would work to get the menu to display www.domain.com/. The code below is what I’m using to run the baseline test. Anyone have a better idea of where I could either intercept this url writing in the menus or rewite it after it has already been written?

    $e = &$modx->Event;
    
    switch ($e->name) 
    {
      case "OnWebPageComplete":
        $o = &$modx->documentOutput; // get a reference of the output
        $o = str_replace("http://www.domain.com/index.html","http://www.domain.com",$o);
        break;
      default :
        return; // stop here - this is very important.
        break;
    }
      • 22815
      • 1,097 Posts
      Ah, but the link in the html is most likely to /index.html, rather than the full thing.
      It will be easiest to add this code in at the point that a FURL is created, as there we have the document ID number that can be compared to site_home.
        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!
        • 22303 MODX Staff
        • 10,725 Posts
        The url rewriting is done towards the end of the parsing process, and the only event you could use to alter them is OnWebPagePrerender. But they would already rewritten at that point, so you’d have to replace the already rewritten URLs
          • 13993
          • 100 Posts
          The url rewriting is done towards the end of the parsing process, and the only event you could use to alter them is OnWebPagePrerender. But they would already rewritten at that point, so you’d have to replace the already rewritten URLs

          The problem is that they are being written for the index page to www.domain.com/index.html.

          I need that one link written to www.domain.com (no page reference).

          I figured out why my code wasnt working though. I was searching for the full domain/url. All that was in the href tags was the page. I’ll update the code later and then get some feedback. I think the solution may create future problems but I need to have it tested.
            • 13993
            • 100 Posts
            Ok I have updated the code again. I fixed the issue with $_GET urls. The query string is now added back to the end of the strict urls. I still want to end up making blog.html?start=2 show a static url. i will figure out a structure soon I hope.

            Current Features
            # 301 Redirect from /index.php?id=8 to /alias.html
            # 301 Redirect from /page, /page/ to /page.html
            # 301 Redirect from non domain.com url to www.domain.com url (requires .htaccess edit)
            # If you switch Friendly URLs off, it redirects /page.html and /page to /index.php?id=48 - this enforces the options that have been selected.
            # 301 Redirect /{site_start}, /{site_start}.html to root folder / (no page in url)
            # Menu links pointing to "www.domain.com/{start_page}" are changed to "www.domain.com" (Can turn off)
              • 22815
              • 1,097 Posts
              Does index.html?start=2 work? Looks like it won’t... Other than that minor matter, great work.

              So. You have a goal of turning blog.html?start=2 into blog2.html. Great goal.

              Now. Turning the "blog.html?start=2" that a page outputs into "blog2.html" is, in principle, doable with the OnWebPagePrerender. But where is it going to get that replace rule from? There needs to be a list of rules somewhere -either specific (blog.html?start=2 = blog2.html) or generic (blog.html?start=[X] = blog[X].html). I’ll come back to that.

              Lets say someone clicks on a blog2.html link.. MODx doesn’t have a page "blog2", so it would 404. We need to run something after the normal MODx document-ID-find routine that will look through the list the other way and find the normal alias and the GET string. Given blog2.html, it needs to set the ID based on "blog" and set various values in $_GET.. then everything should work.

              So both of these sides are highly dependent on there being a lookup table for desired SEO overwrites... to me, this seems like a job for a db table that you can add to in a Manager module. This would be quite a cool feature to have. The questions then arise of how far things should be generic / automated. Is it easier/quicker to pregenerate blog2, blog3, blog-august-2006 etc, or to look for rules and build up matches? I think the first step has to be manually entered page overrides.

              --

              Of course, search engines *will* index blog.html?page=2, but I can see that there is an optimisation benefit. I’ve never personally had much trouble getting non-static pages indexed well; switching a non-generic title (eg product name instead of just shop name) seems to be the best SEO change I’ve ever made to dynamic systems. Indeed, I don’t particularly care if the 2nd page of blog summaries is indexed, as long as the documents it references have been crawled. But there are situations in which replacing dynamic URLs with fake static ones will be good. I’m watching this plugin with keen interest.
                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!
                • 13993
                • 100 Posts
                I have updated the code again. www.domain.com/?start=2 & www.domain.com/index.html?start=2 should now work. Let me know. www.domain.com/index.html still redirects to base dir. i’m thinking of redirecting www.domain.com/?start=2 to www.domain.com/index.html?start=2.

                I am looking into the options for the static urls. That part is a lot more complicated then the rest of the code. It would be easy if it was the core that was being edited but doing it via a plugin is not so simple. I’ll keep the thread updated on it. I’ll probably work on the directory features first.

                I also need some more beta testers. I specifically need the following types of tests.

                1. Tests on 0.9.2 platforms.
                2. Tests with modx installed in a sub directory like www.domain.com/modx_install/

                Any takers out there? I have a feeling something will break in both of these.
                  • 22815
                  • 1,097 Posts
                  You can’t do the redirect in the same way in 0.9.2 -
                        header("HTTP/1.1 301 Moved Permanently");
                        header('Location: ' . $myDomain);

                  is a new feature in 0.9.5. So there’s no point testing it in anything prior to that.
                    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!
                    • 13993
                    • 100 Posts
                    Isn’t that straight PHP code? How can it be version specific?

                    http://us2.php.net/header
                      • 22815
                      • 1,097 Posts
                      Sorry, what I mean is that the ability to use this is new. Prior MODx versions had already set the headers earlier on. Or something.
                        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!