We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 37059
    • 368 Posts
    Quote from: markg at Mar 14, 2011, 07:09 PM

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

    You may be right, though I’m afraid a brighter PHP light than I would be needed to figure out why. Offhand, I can’t think why code that clearly generates a 301 is coming out a 302.
      Jason
      • 12320
      • 88 Posts
      i invite you to check your installation of virtual aliases because mine give 301 redirect :
      http://www.maatel.com/fr/produits

      virtual aliases :
      //<?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;
        $tableau =array();
        //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"];
           }
        }
      //die(var_export($tableau));
        if ($found)  // Redirect to new document, if an alias was found
        {
      
           $pageUrl = $modx->makeUrl($found, '', '', "full");
           //$modx->sendRedirect($pageUrl, 0, "REDIRECT_HEADER", "301");  // Send a permanent redirect with error on IE7
           $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");
      }
      
      

      SEO Strict URLs :
      //<?php
      // Strict URLs
      // version 1.0.1
      // Enforces the use of strict URLs to prevent duplicate content.
      // By Jeremy Luebke @ www.xuru.com
      // Contributions by Brian Stanback @ www.stanback.net
      
      // On Install: Check the "OnWebPageInit" & "OnWebPagePrerender" boxes in the System Events tab.
      // Plugin configuration: &editDocLinks=Edit document links;int;1 &makeFolders=Rewrite containers as folders;int;1 &emptyFolders=Check for empty container when rewriting;int;0 &override=Enable manual overrides;int;0 &overrideTV=Override TV name;string;seoOverride
      
      // 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] 
      
      // Begin plugin code
      $e = &$modx->event;
      
      if ($e->name == 'OnWebPageInit') 
      {
         $documentIdentifier = $modx->documentIdentifier;
      
         if ($documentIdentifier)  // Check for 404 error
         {
            $myProtocol = ($_SERVER['HTTPS'] == 'on') ? 'https' : 'http';
            $s = $_SERVER['REQUEST_URI'];
            $parts = explode("?", $s);  
      
            $alias = $modx->aliasListing[$documentIdentifier]['alias'];
            if ($makeFolders)
            {
               if ($emptyFolders)
               {
                  $result = $modx->db->select('isfolder', $modx->getFullTableName('site_content'), 'id = ' . $documentIdentifier);
                  $isfolder = $modx->db->getValue($result);
               }
               else
               {
                  $isfolder = (count($modx->getChildIds($documentIdentifier, 1)) > 0) ? 1 : 0;
               }
            }
      
            if ($override && $overrideOption = $modx->getTemplateVarOutput($overrideTV, $documentIdentifier))
            {
               switch ($overrideOption[$overrideTV])
               {
                  case 0:
                     $isoverride = 1;
                     break;
                  case 1:
                     $isfolder = 0;
                     break;
                  case 2:
                     $makeFolders = 1;
                     $isfolder = 1;
               }
            }
      
            if ($isoverride)
            {
               $strictURL = preg_replace('/[^\/]+$/', $alias, $modx->makeUrl($documentIdentifier));
            }
            elseif ($isfolder && $makeFolders)
            {
               $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'])
            {
               if ($requestedURL != $modx->config['site_url'])
               {
                  // Force redirect of site start
                  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(0);
               }
            }
            elseif ($parts[0] != $strictURL)
            {
               // Force 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(0);
            }
         }
      }
      elseif ($e->name == 'OnWebPagePrerender')
      {
         if ($editDocLinks)
         {
            $myDomain = $_SERVER['HTTP_HOST'];
            $furlSuffix = $modx->config['friendly_url_suffix'];
            $baseUrl = $modx->config['base_url'];
            $o = &$modx->documentOutput; // get a reference of the output
      
            // Reduce site start to base url
            $overrideAlias = $modx->aliasListing[$modx->config['site_start']]['alias'];
            $overridePath = $modx->aliasListing[$modx->config['site_start']]['path'];
            $o = preg_replace("#((href|action)=\"|$myDomain)($baseUrl)?($overridePath/)?$overrideAlias$furlSuffix#", '${1}' . $baseUrl, $o);
      
            if ($override)
            {
               // Replace manual override links
               $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))
               {
                  $overrideAlias = $modx->aliasListing[$row['id']]['alias'];
                  $overridePath = $modx->aliasListing[$row['id']]['path'];
                  switch ($row['value'])
                  {
                     case 0:
                        $o = preg_replace("#((href|action)=\"($baseUrl)?($overridePath/)?|$myDomain$baseUrl$overridePath/?)$overrideAlias$furlSuffix#", '${1}' . $overrideAlias, $o);
                        break;
                     case 2:
                        $o = preg_replace("#((href|action)=\"($baseUrl)?($overridePath/)?|$myDomain$baseUrl$overridePath/?)$overrideAlias$furlSuffix/?#", '${1}' . rtrim($overrideAlias, '/') . '/', $o);
                        break;
                  }
               }
            }
      
            if ($makeFolders)
            {
               if ($emptyFolders)
               {
                  // Populate isfolder array
                  $isfolder_arr = array();
                  $result = $modx->db->select('id', $modx->getFullTableName('site_content'), 'published > 0 AND isfolder > 0');
                  while ($row = $modx->db->getRow($result))
                     $isfolder_arr[$row['id']] = true;
               }
      
               // Replace container links
               foreach ($modx->documentListing as $id)
               {
                  if ((is_array($isfolder_arr) && isset($isfolder_arr[$id])) || count($modx->getChildIds($id, 1)))
                  {
                     $overrideAlias = $modx->aliasListing[$id]['alias'];
                     $overridePath = $modx->aliasListing[$id]['path'];
                     $o = preg_replace("#((href|action)=\"($baseUrl)?($overridePath/)?|$myDomain$baseUrl$overridePath/?)$overrideAlias$furlSuffix/?#", '${1}' . rtrim($overrideAlias, '/') . '/', $o);
                  }
               }
            }
         }
      }
      

      regards
        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
        Where did you get that version from?

        I can’t see it on Stanback’s site it only has o.o.2
          Content Creator and Copywriter
          • 12320
          • 88 Posts
          I’ve start writing my own, but i gave it back to Stanback, but he never answear me ...

          so i share it here ...



            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
            OH PS

            I’m on Evo, I did mention that at the start of my question.


            I see now that this seems to be a Revo forum, or doesn’t it matter?
              Content Creator and Copywriter
              • 12320
              • 88 Posts
              on my mind, this part of the forum is not separated in version ...

              my code is for Evo too
                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
                OK,

                tried your code, made no difference, still getting 302’s.

                Got me beat.

                  Content Creator and Copywriter
                  • 12320
                  • 88 Posts
                  show me your htaccess please, i ll try to support you
                    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
                    Actually

                    it seems to have mostly worked apart from a few urls still showing as 302’s.

                    Give me a few minutes and I’ll see if I can fix them.

                      Content Creator and Copywriter
                      • 18367
                      • 834 Posts
                      OK,

                      I’m down to three errant 302’s from the hundred or so I had earlier.

                      Here’s my errant 302’s
                      http://makethemclick.com.au/about
                      redirected to: http://makethemclick.com.au/about/who-we-are
                      status code: 302 (object temporarily moved)
                      linked from page(s):
                      http://makethemclick.com.au/help/site-map

                      http://makethemclick.com.au/help
                      redirected to: http://makethemclick.com.au/help/site-map
                      status code: 302 (object temporarily moved)
                      linked from page(s):
                      http://makethemclick.com.au/help/site-map

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

                      The first two are actually being redirected by First Child Redirect as they are folders, might have to head over to that support thread.

                      The last one is obviously the homepage and I’ve no idea why that isn’t redirecting as a 301.


                      Anyway, here’s my htacess file
                      
                      RewriteCond %{HTTP_HOST} ^www.makethemclick.net [NC]
                      RewriteRule ^(.*)$ http://makethemclick.com.au/$1 [L,R=301]
                      
                      RewriteCond %{HTTP_HOST} ^makethemclick.com.au/index [NC]
                      RewriteRule ^(.*)$ http://makethemclick.com.au/$1 [L,R=301]
                      
                      RewriteCond %{HTTP_HOST} ^makethemclick.com.au/library/online-marketing/kill-online-marketing-guru/ [NC]
                      RewriteRule ^(.*)$ http://makethemclick.com.au/library/online-marketing/kill-your-online-marketing-guru$1 [L,R=301]
                      
                      Options +FollowSymLinks
                      RewriteEngine On
                      RewriteBase /
                      RewriteCond %{REQUEST_FILENAME} !-f
                      RewriteCond %{REQUEST_FILENAME} !-d
                      
                      RewriteRule ^(.*)$ /index.php?q=$1 [L,QSA]
                      
                      php_flag register_globals Off
                      
                      php_flag zlib.output_compression on

                        Content Creator and Copywriter