We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 2611
    • 394 Posts
    This is an auto-generated topic for Virtual Aliases 1.0-rc1 by b03tz.

    Description

    Allows old URL’s to be transfered to a new website with 301 "Permanently moved" headers. This script is based on the one from "Brian Stanback" (stanback.net).
    Instructions

    * Copy the plugin to your REVO and check the event "onPageNotFound"
    * Create a template variable that hold’s the OLD url and remember it’s ID
    * Create a property in the DEFAULT property set called "tvId" and give it the value of the TV
    * Fill in the old URL’s of your pages in the corresponding resources without the beginning slash.
    * Test it out by visiting yoursite.com/old-url.html and it should work.

      Follow me on twitter: @b03tz
      Follow SCHERP Ontwikkeling on twitter: @scherpontwikkel
      CodeMaster
      • 33337
      • 3,975 Posts
      Hi b03tz,

      It seems to take me on the page, but it doesnt set proper headers, also doesnt change the url in the address bar.

      Web Developer toolbar gives "404 Not Found" in response headers.


      Ok it seems to work ok with a single url but not with multiple urls.

      Looks like there is no support for multiple urls? Is that true?
        Zaigham R - MODX Professional | Skype | Email | Twitter

        Digging the interwebs for #MODX gems and bringing it to you. modx.link
        • 18367
        • 834 Posts
        When I check the redirects they are all showing up as 302’s.

        Is there any way to make Virtual Aliases use 301’s
          Content Creator and Copywriter
          • 37059
          • 368 Posts
          Quote from: markg at Feb 18, 2011, 02:08 AM

          When I check the redirects they are all showing up as 302’s.

          Are you sure about that? I just checked mine using Firebug’s Net panel, and it is showing 301’s.
            Jason
            • 12320
            • 88 Posts
            I made a modification on this script for regexp support
            there s also a fix on the 301 redirect error on ie7

            Thanks for this code
            thanks too to publish it

            //<?php
            // Virtual Aliases
            // version 0.0.1
            // Allows for an unlimited number of custom aliases per page.
            // By Brian Stanback @ www.stanback.net
            
            // On Install: Check the the "OnPageNotFound" box in the System Events tab.
            // Plugin configuration: &aliasesTV=Aliases TV name;string;Aliases
            
            // For overriding documents, create a new template variabe (TV) named
            // Aliases with the following option:
            //    Input Type: Textarea (Smaller)
            //
            // Aliases should be added to the TV, one per line.
            // Omit any leading or trailing slashes as well as the default suffix (usaully .html)
            
            // Begin plugin code
            $e = &$modx->event;
            
            if ($e->name == "OnPageNotFound")
            {
              // Retrieve requested path + alias
              $documentAlias = $modx->documentIdentifier;
              $documentAlias = ($modx->virtualDir == "") ? $documentAlias : $modx->virtualDir . '/' . $documentAlias;
            echo "Alias : ".$documentAlias."<br/>";
              // Search TVs for potential alias matches
              $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 = '$aliasesTV'";
              $results = $modx->db->query($sql);
              // Attempt to find an exact match
              $found = 0;
              //debug	$tableau[] =$documentAlias ;
              while ($found == 0 && $row = $modx->db->getRow($results))
              {
                 $pageAliases = explode("\n", $row["value"]);
                 while ($found == 0 && $alias = each($pageAliases))
                 {
                 $alias[1] = trim($alias[1]);
                 	if (strlen($alias[1])>0 && $alias[1][0] == "#") {
            		$out = preg_match($alias[1], $documentAlias);
            		$returnValue = (!empty($out))? count($out)>0: false;
            	} else {
            	$returnValue = false; 
            	}
            	if (($alias[1] == $documentAlias ) || $returnValue )  // Check for a match
                       $found = $row["id"];
                 }
              }
              if ($found)  // Redirect to new document, if an alias was found
              {
            
                 $pageUrl = $modx->makeUrl($found, '', '', "full");
                 $modx->sendRedirect($pageUrl, 0, "REDIRECT_HEADER", 'HTTP/1.1 301 Moved Permanently');      exit(0);
              }
            
              header("HTTP/1.0 404 Not Found");
              header("Status: 404 Not Found");
            }
            
            


            regards, Focoweb.fr
              Thanks to the authors of the following code :
              Easy Newsletter (module)
              SiteMap (snippet)
              Codepress (Plugins)
              Strict URLs (Plugins)
              Virtual Aliases (Plugins)
              Maxygallery (snippet)
              • 37059
              • 368 Posts
              Isn’t that the Evo version?
                Jason
                • 12320
                • 88 Posts
                yes it is.
                but there are minor differences with revo
                  Thanks to the authors of the following code :
                  Easy Newsletter (module)
                  SiteMap (snippet)
                  Codepress (Plugins)
                  Strict URLs (Plugins)
                  Virtual Aliases (Plugins)
                  Maxygallery (snippet)
                  • 18367
                  • 834 Posts
                  Ken,

                  when I check with Xenu all my Virtual Aliases are showing as 302’s

                  The few I have done via htaccess are all fine as 301’s

                  I’m on Evo

                  Is there some configuration option I need to check or is it a bug somewhere?
                    Content Creator and Copywriter
                    • 37059
                    • 368 Posts
                    Quote from: markg at Mar 13, 2011, 07:52 PM

                    when I check with Xenu all my Virtual Aliases are showing as 302’s

                    Could you share a link to the site where the problem is occuring? The 301 is hard-coded into the PHP.
                      Jason
                      • 18367
                      • 834 Posts

                      Here’s just one for the home page.

                      http://makethemclick.com.au/index
                      redirected to: http://makethemclick.com.au/
                      status code: 302 (object temporarily moved)

                      and here’s what it looks like in the Aliases field for the document
                      index.php
                      home
                      /index.htm
                      index.html

                      It seems to be doing it for every alias I use

                      I beginning to suspect the problem may be with my host, but I don;t know how to prove it.


                        Content Creator and Copywriter