We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 13993
    • 100 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.

    I installed both 0.9.2 and 0.9.5 in a subdir to test both. Yea 0.9.2 completely breaks with all kinds of errors anyway. So I’m not even gonna bother with it.

    The 0.9.5 in the subdir seems to work ok though.

    I think I broke the following though.

    # 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.

    Can anyone confirm this no longer works with the new code?
      • 13993
      • 100 Posts
      I have updated the code again. I fixed some bugs dealing with ModX installed in a sub directory.
        • 13993
        • 100 Posts
        Ok I have updated the code again. The code can now force directories to be redirected to /dir/ from /pre.dir.suff

        I turned it off by default since I have been unable to rewrite the urls in the html completely yet.

        # Make blog.html?start=2 look like blog2.html or something like it.
        This shoulce be implemented and it will be easy in the core but I am now of the opinion that it cannot be done through a plugin. In the end the urls will probably look like blog-start-2.html or something similar.

        # Strip .post_extension from any non html page
        Is there a functuion I can call to see if a file / folder is marked as being html rather then css or the like? Or do I need to pull that info from the database also?


        I have discovered a few more bugs and limitations. I can enforce the correct urls with ease, but rewriting of urls in the html that have already been written via the core functions is starting to seem futile. I think I may have reached the limit of what I can do with the current core.

        I would just modify the core to create the new URLs in the documents and then submit it to see if I could get it added to the next release, but OpenGeek mentioned that the URL rewriting was being moved to an external class to make it easier to interact with so that might be a waste. OpenGeek, what would you recommend. You mentioned the new class soon. Is it something already in the trunk but not in the beta 2 release? Is it something that will be included in the 0.9.5 final release?

          • 22303 MODX Staff
          • 10,725 Posts
          Quote from: JeremyL at Sep 25, 2006, 08:52 PM
          I have discovered a few more bugs and limitations. I can enforce the correct urls with ease, but rewriting of urls in the html that have already been written via the core functions is starting to seem futile. I think I may have reached the limit of what I can do with the current core.
          Exactly the motivation for the core rewrite that I am working on and keep mentioning. There’s rewriting logic all over the place and you really can’t cover all the scenarios without changing the core.

          Quote from: JeremyL at Sep 25, 2006, 08:52 PM
          I would just modify the core to create the new URLs in the documents and then submit it to see if I could get it added to the next release, but OpenGeek mentioned that the URL rewriting was being moved to an external class to make it easier to interact with so that might be a waste. OpenGeek, what would you recommend. You mentioned the new class soon. Is it something already in the trunk but not in the beta 2 release? Is it something that will be included in the 0.9.5 final release?
          This is not in the current code at all, and will not be in 0.9.5. I definitely recommend working out your logic issues in the current trunk and submitting it as a contribution; this will not be wasted effort. We will definitely review it and incorporate it as appropriate, and you can rest assured, whatever you contribute will also be functionally incorporated into the new code. Don’t let progress deter progress, that’s my motto. wink

          For now, the new code is available only to the team and is 100% independent of the current codebase (completely rewritten from scratch). I am working on finishing up adjustments to some licensing verbiage, and synchronizing the new code with the latest 0.9.5 features and bug fixes and will make it available publically shortly after 0.9.5 final is out the door.
            • 30277
            • 75 Posts
            I come across http://modxcms.com/forums/index.php/topic,10110.0.html

            Is this project alive or dead ?
              • 1932
              • 137 Posts
              Thanks for creating this extremely useful plugin. I’m interested to see how things work out in the new codebase.

              I wanted to do some individual URL and link rewriting. For example, I want my rss feed to default to feed.rss, not feed.rss.html. Also, I want my menu links to link directly to the folder name rather than having to go through an extra level of redirects.


              Below are my simple revisions to the current code. As mentioned above, the link rewriting code would benefit from an actual URL parser but a simple string replace seems to do the trick in most scenarios. I have modified the code to include two new configuration parameters: $override and $editOverrideLinks. The below code is has been tested and appears to work on the current SVN trunk (should work with at least 0.9.5), let me know what you guys think.
                • 23491 ☆ A M B ☆
                • 1,056 Posts
                @ApoXX,

                Very useful Mod! What about introducing a TV (checkbox/dropdown?) to the scene so a user can simply click on/off to override the extension w/o having to modify the code... I love the direction with this! wink
                  Mike Reid - www.pixelchutes.com
                  MODx Ambassador / Contributor
                  [Module] MultiMedia Manager / [Module] SiteSearch / [Snippet] DocPassword / [Plugin] EditArea / We support FoxyCart
                  ________________________________
                  Where every pixel matters.
                  • 1932
                  • 137 Posts
                  Great suggestion, I’ve run across a couple of issues while attempting to integrate the config as a TV:

                  I was trying to get TV assigned to the rss feed. I can’t assign a TV to the default (blank) template and when I try to associate it to a new, blank template, MODx gives me a parsing error. Is it possible to associate a TV with the XML feed?

                  Also, in order for html/link rewriting to work, I would have to loop through every non-default TV value in the database.. I suppose I could either do this with a raw SQL query or perhaps there is an API call that would do it.

                  Edit: There seems to be a compatibility issue with my AutoLink plugin and custom feeds, I have disabled it for now and my custom feeds are working.
                    • 23491 ☆ A M B ☆
                    • 1,056 Posts
                    Hmmm...I wonder, couldn’t you just create an empty template (with JUST [*content*]), solely for the purpose of assigning TVs? For XML feed, you can still change the content type to XML smiley

                    Let me know!

                    UPDATE: I have a working example of Blank TPL, XML content type, and TVs working here: http://www.pixelchutes.com/xml.rss
                      Mike Reid - www.pixelchutes.com
                      MODx Ambassador / Contributor
                      [Module] MultiMedia Manager / [Module] SiteSearch / [Snippet] DocPassword / [Plugin] EditArea / We support FoxyCart
                      ________________________________
                      Where every pixel matters.
                      • 1932
                      • 137 Posts
                      Note: Experimental release

                      Okay, I whipped up some new code that reads a Template Variable rather than a configurable array.

                      Installation:

                      1) Create a new Plugin and copy and paste the below PHP code.
                      2) In the System Events Tab check "OnWebPageInit" & "OnWebPagePrerender"
                      3) Create a new Template Variable, the default name is seoOverride but this can be modified by editing the configuration option in the plugin’s php code.
                      4) Select DropDown List Menu for the Input Type and enter "Disabled==-1||Base Name==0||Append Extension==1||Folder==2" for Input Option Values (excluding quotes).
                      5) Check the desired templates to associate the new Template Variable with them.

                      Finally, edit your pages, modifying the new Template Variable to override rewrite preferences.

                      NOTE: Remove the first <?php and last ?> from the code when saving as a plugin.

                      <?php
                      // Strict URLs
                      // version 0.7.2
                      // Enforces the use of strict urls to prevent dup content.
                      // By Jeremy Luebke @ www.xuru.com
                      //   Override configuration added by Brian Stanback @ www.stanback.net
                      
                      // On Install: Check the "OnWebPageInit" & "OnWebPagePrerender" boxs in the System Events tab.
                      
                      // For overriding documents, create a new template variabe (TV) named seoOverride with the following options:
                      //    Input Type: DropDown List Menu
                      //    Input Option Values: Disabled==-1||Base Name==0||Append Extension==1||Folder==2
                      //    Default Value: -1
                      
                      //  # Include the following in your .htaccess file
                      //  # Replace "example.com" &  "example\.com" with your domain info
                      //  RewriteCond %{HTTP_HOST} .
                      //  RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
                      //  RewriteRule (.*) http://www.example.com/$1 [R=301,L] 
                      
                      // Config //
                      $editMenuLinks = 1; // Set to 1 to manipulate menu links. Set to 0 to leave them alone
                      $makeFolder = 0; // Set to 1 to enforce folders to display as /dir/ and not /dir.html
                      
                      $override = 1; // Enable manual overrides
                      $overrideTV = "seoOverride"; // Name of the template var that contains the override value
                      $editOverrideLinks = 1; // Set to 1 to manipulate links for overridden documents. Set to 0 to leave them alone
                      $editOverrideCase = ""; // Set to "" to replace links beginning with lower case href= only or "i" to replace all cases of href (slower)
                      
                      // Start Main Code //
                      
                      $e = &$modx->event;
                      
                      if($e->name=='OnWebPageInit') 
                      {
                         $myProtocol = $_SERVER['HTTPS'] == on ? "https" : "http";  // Replace with $myProtocol = $modx->config['server_protocol'] to force the configured protocol
                      
                         $s = $_SERVER['REQUEST_URI'];
                         $parts = explode("?", $s);  
                      
                         $documentIdentifier = ($modx->documentIdentifier) ? $modx->documentIdentifier : $modx->config['error_page'];  // Set error page document ID if page is not found
                      
                         $results = $modx->db->select("isfolder, alias", $modx->getFullTableName('site_content'), "id = " . $documentIdentifier);
                         $row = $modx->fetchRow($results);
                         $isfolder = $row['isfolder'];
                         $alias = $row['alias'];
                      
                         if ($override && $overrideOption = $modx->getTemplateVarOutput($overrideTV,$documentIdentifier))
                         {
                            switch ($overrideOption[$overrideTV])
                            {
                               case 0:
                                  $isoverride = 1;
                                  break;
                               case 1:
                                  $isfolder = 0;
                                  break;
                               case 2:
                                  $makeFolder = 1;
                                  $isfolder = 1;
                            }
                         }
                      
                         if ($isoverride)
                         {
                            $strictURL = preg_replace('/[^\/]+$/', $alias, $modx->makeUrl($documentIdentifier));
                         }
                         elseif($isfolder && $makeFolder)
                         {
                            $strictURL = preg_replace('/[^\/]+$/', $alias, $modx->makeUrl($documentIdentifier)) . "/";
                         }
                         else
                         {
                            $strictURL = $modx->makeUrl($documentIdentifier);
                         }
                      
                         $myDomain = $myProtocol . "://" . $_SERVER['HTTP_HOST'];
                      
                         $newURL = $myDomain . $strictURL;
                         $requestedURL = $myDomain . $parts[0];
                      
                         if($documentIdentifier == $modx->config['site_start'] && $requestedURL != $modx->config['site_url'])
                         {
                            // Force use of root redirect
                            header("HTTP/1.1 301 Moved Permanently");
                            $qstring = preg_replace("#(^|&)(q|id)=[^&]+#", '', $parts[1]);  // Strip conflicting id/q from query string
                            if ($qstring) header('Location: ' . $modx->config['site_url'] . '?' . $qstring);
                            else header('Location: ' . $modx->config['site_url']);
                            exit;
                         }
                         elseif($parts[0] != $strictURL && $documentIdentifier != $modx->config['site_start'])
                         {
                            // Force specific page redirect
                            header("HTTP/1.1 301 Moved Permanently");
                            $qstring = preg_replace("#(^|&)(q|id)=[^&]+#", '', $parts[1]);  // Strip conflicting id/q from query string
                            if ($qstring) header('Location: ' . $strictURL . '?' . $qstring);
                            else header('Location: ' . $strictURL);
                            exit;
                         }
                      }
                      elseif($e->name=='OnWebPagePrerender')
                      {
                         if ($editMenuLinks)
                         {
                            $o = &$modx->documentOutput; // get a reference of the output
                            $base_str = basename($modx->makeUrl($modx->config['site_start']));
                            $o = preg_replace("#/?$base_str#",$modx->config['base_url'],$o);
                         }
                      
                         if ($override && $editOverrideLinks)
                         {
                            if (!$editMenuLinks) $o = &$modx->documentOutput; // get a reference of the output
                            $myDomain = $_SERVER['HTTP_HOST'];
                      
                            $sql = "SELECT tvc.contentid as id, tvc.value as value FROM " . $modx->getFullTableName('site_tmplvars') . " tv ";
                            $sql .= "INNER JOIN " . $modx->getFullTableName('site_tmplvar_templates') . " tvtpl ON tvtpl.tmplvarid = tv.id ";
                            $sql .= "LEFT JOIN " . $modx->getFullTableName('site_tmplvar_contentvalues') . " tvc ON tvc.tmplvarid = tv.id ";
                            $sql .= "LEFT JOIN " . $modx->getFullTableName('site_content') . " sc ON sc.id = tvc.contentid ";
                            $sql .= "WHERE sc.published = 1 AND tvtpl.templateid = sc.template AND tv.name = '$overrideTV'";
                            $results = $modx->dbQuery($sql);
                            while ($row = $modx->fetchRow($results))
                            {
                               $overrideURL = basename($modx->makeUrl($row['id']));
                               switch ($row['value'])
                               {
                                  case 0:
                                     $o = preg_replace("#(href=\"/?|$myDomain/)$overrideURL#$editOverrideCase", "$1" . str_replace(strrchr($overrideURL, '.'), '', $overrideURL),$o);
                                     break;
                                  case 2:
                                     $o = preg_replace("#(href=\"/?|$myDomain/)$overrideURL#$editOverrideCase", "$1" . str_replace(strrchr($overrideURL, '.'), '/', $overrideURL),$o);
                                     break;
                               }
                            }
                         }
                      }
                      else
                      {
                          return;
                      }
                      ?>
                      


                      The $editOverrideLinks option is still pretty experimental. In the future, it would be worthwhile to write/use a dedicated parser class for possible gains in efficiency as well as proper editing/replacing of relative links (../somedoc.html) and support for nested alias parsing.

                      @Edit:
                      I modified the code to use the API for database calls and table name/prefix derivation.

                      I also added support for query string forwarding on redirects (needed for some snippets, such as QuickEdit to work). The id and q parameters are stripped from the resulting query string upon initial forward.