Jump to content
tgely

Fake URL redirection by administration

Recommended Posts

I think there would be a lesson learned here is that you don't simply delete a product, but set up something to send any old incoming link to either a similar product or to a product category. In either case, there should be some message to the visitor that the original product is no longer available, but here is something similar/here is a useful category. I suppose it's possible that there could be nothing appropriate to send a customer to, but they should still get a message of some sort explaining the situation, and making suggestions for alternatives. Hopefully this can be done in a way that Google doesn't ding you for duplicate content, or whatever.

Share this post


Link to post
Share on other sites

I think there would be a lesson learned here is that you don't simply delete a product, but set up something to send any old incoming link to either a similar product or to a product category. In either case, there should be some message to the visitor that the original product is no longer available, but here is something similar/here is a useful category. I suppose it's possible that there could be nothing appropriate to send a customer to, but they should still get a message of some sort explaining the situation, and making suggestions for alternatives. Hopefully this can be done in a way that Google doesn't ding you for duplicate content, or whatever.

Yes Phil this is would be a good way. I thought an optional message field in the datatable and display it after redirection by messagestack.


:blink:
osCommerce based shop owner with minimal design and focused on background works. When the less is more.
Email managment with tracking pixel, package managment for shipping, stock management, warehouse managment with bar code reader, parcel shops management on 3000 pickup points without local store.

Share this post


Link to post
Share on other sites

Hi all,

 

next release is pushed on. Nothing to do only upload admin files and hit the url redirection menu.

 

@@altoid

 

There is a wildcard * solution for more redirections in one step. Did you see it?

Does csv downloads/uploads work for you?

@@Gergely

 

I've gotten so used to using phpMyAdmin for url redirect management I really haven't worked with the csv much.  But I did try a download a couple days ago, it rendered with semi-colon delimiters and not a csv type that places each field into an Excel column, but I'll revisit that again for testing purposes.


I am not a professional webmaster or PHP coder by background or training but I will try to help as best I can.

I remember what it was like when I first started with osC. It can be overwhelming.

However, I strongly recommend considering hiring a professional for extensive site modifications, site cleaning, etc.

There are several good pros here on osCommerce. Look around, you'll figure out who they are.

Share this post


Link to post
Share on other sites

If someone would like to test message_stack redirection than install first the Mesage Stack Notifications header module.

 

 

Hard coded testing mod in URL redirection addon:

includes/modules/url_redirects/redirects_handler.php

 

change

  function http_error_handler($error_id = '999') {
    global $request_type, $requested_url, $HTTP_GET_VARS, $PHP_SELF;
to

  function http_error_handler($error_id = '999') {
    global $request_type, $requested_url, $HTTP_GET_VARS, $PHP_SELF, $messageStack;
change:

 

        if (tep_not_null($redirect['new_url']) && $redirect['url_redirects_status'] == 1) {
          // self or foreign host?
          $host = ((preg_match('[://]', $redirect['new_url'])) ? "" : ($request_type == 'SSL' ? HTTPS_SERVER : HTTP_SERVER));

          //header("HTTP/1.0 301 Moved Permanently");
          header("Location: " . $host . $redirect['new_url'] . "", TRUE, $redirect['url_redirects_mode']);
          exit();
To:

 

        if (tep_not_null($redirect['new_url']) && $redirect['url_redirects_status'] == 1) {
          // self or foreign host?
          $host = ((preg_match('[://]', $redirect['new_url'])) ? "" : ($request_type == 'SSL' ? HTTPS_SERVER : HTTP_SERVER));

          // add messages for users
          $messageStack->add_session('header', 'The original product/category is no longer available, but we redirect you which is similar/here is a useful category.', 'success');

          //header("HTTP/1.0 301 Moved Permanently");
          header("Location: " . $host . $redirect['new_url'] . "", TRUE, $redirect['url_redirects_mode']);
          exit();
Edited by Gergely
better instructions

:blink:
osCommerce based shop owner with minimal design and focused on background works. When the less is more.
Email managment with tracking pixel, package managment for shipping, stock management, warehouse managment with bar code reader, parcel shops management on 3000 pickup points without local store.

Share this post


Link to post
Share on other sites

With that I end up here:

 

/http_error.php?error_id=302

 

Rather than at the intended redirect url.

 

If I remove the test code, all is OK again.


I am not a professional webmaster or PHP coder by background or training but I will try to help as best I can.

I remember what it was like when I first started with osC. It can be overwhelming.

However, I strongly recommend considering hiring a professional for extensive site modifications, site cleaning, etc.

There are several good pros here on osCommerce. Look around, you'll figure out who they are.

Share this post


Link to post
Share on other sites

sorry my bad I forget something
includes/modules/url_redirects/redirects_handler.php

change

  function http_error_handler($error_id = '999') {
    global $request_type, $requested_url, $HTTP_GET_VARS, $PHP_SELF;

to

  function http_error_handler($error_id = '999') {
    global $request_type, $requested_url, $HTTP_GET_VARS, $PHP_SELF, $messageStack;

:blink:
osCommerce based shop owner with minimal design and focused on background works. When the less is more.
Email managment with tracking pixel, package managment for shipping, stock management, warehouse managment with bar code reader, parcel shops management on 3000 pickup points without local store.

Share this post


Link to post
Share on other sites

Ran the "Old URL Testing for a product and category, the message shows in the header as so:

 

post-231701-0-32402700-1434046564_thumb.jpg

 

 


I am not a professional webmaster or PHP coder by background or training but I will try to help as best I can.

I remember what it was like when I first started with osC. It can be overwhelming.

However, I strongly recommend considering hiring a professional for extensive site modifications, site cleaning, etc.

There are several good pros here on osCommerce. Look around, you'll figure out who they are.

Share this post


Link to post
Share on other sites

the fiel url_redirects_status was not updated, after the upload from the csv file.

 

all other fields are updated...

Share this post


Link to post
Share on other sites

Ran the "Old URL Testing for a product and category, the message shows in the header as so:

 

attachicon.gifredirect.jpg

 

:thumbsup:

 

The next question is what should be the message?


:blink:
osCommerce based shop owner with minimal design and focused on background works. When the less is more.
Email managment with tracking pixel, package managment for shipping, stock management, warehouse managment with bar code reader, parcel shops management on 3000 pickup points without local store.

Share this post


Link to post
Share on other sites

the fiel url_redirects_status was not updated, after the upload from the csv file.

 

all other fields are updated...

I see the problem. I used openoffice calc but the excell could be the same. Download standard in coma delimited "" and semicolumn ; column separated key file but when I saved it replaced with TAB column separated and non delimited.

 

 

In standard URLs the following characters are allowed:

 

ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~:/?#[]@!$&'()*+,;=

URL redirection export-import .csv should be TSV (tab separated values) standard.

 

 

Could you test with this new standard file? I dont have excell.

 

[your_admin]/ext/modules/csv/csvExpImp.php

<?php
/*
  Copyright by Gergely Tóth http://oscom.hu

  v1.1

  Export from query
  1. parse query
  2. get header fields
  3. run query and save results into temporary csv file
  4. download if need
  5. delete temporary file
*/

  define('FS_OUTPUT_PATH', '');

  class export2csv {
    // public variables
    var $filename,
        $lines_terminated,
        $fields_terminated,
        $optionally_enclosed,
        $output,
        $sql_result,
        $tmpfname = '';
    var $inistatus = false;

    // run the export
    //$query could be sql string or object results
    function downloadCsv($query = Null) {

      // default init call from built in $this->inisetCSV() function
      if (!$this->inisatus) {
        $this->inisetCSV();
      }

      if (!$this->filename) {
        $this->setFilename();
      }

      if (!is_object($query)) {
        $this->getResult($query);
      }

      $this->buildDatasheet($this->sql_result);
      $this->downloadFile();
      unlink(FS_OUTPUT_PATH . $this->tmpfname);

    }

    function getResult($query) {
      $this->sql_result = tep_db_query($query);
    }

    function buildHeader($sql_result) {
      // Get The Field Name from query
      while ( $columns = tep_db_fetch_fields($sql_result) ) {
        $this->output .= $this->optionally_enclosed . $columns->name . $this->optionally_enclosed . $this->fields_terminated;
      }
      $this->output .= $this->lines_terminated;
    }

    function buildDatasheet($sql_result) {
      // init
      $this->tmpfname = strftime('%Y%m%d-%H%M%S') . '.csv';
      $fp = fopen(FS_OUTPUT_PATH . $this->tmpfname, "a+");

      // reset output and build csv header line
      $this->setOutput();
      $this->buildHeader($sql_result);

      fwrite($fp, $this->output);

      // Get Records from the query
      while ($row = tep_db_fetch_array($sql_result)) {
        $output = ''; // init and generate rows
        foreach ($row as $key=>$value) {
          $output .= $this->optionally_enclosed . $value . $this->optionally_enclosed . $this->fields_terminated;
        }
        $output .= $this->lines_terminated;
        // save row data into file
        fwrite($fp, $output);
      }

      fclose($fp);
    }

    function downloadFile() {
      // Download the file

      $file_size  = filesize(FS_OUTPUT_PATH . $this->tmpfname);
      $file = @fopen(FS_OUTPUT_PATH . $this->tmpfname,"rb");

      header("Content-Encoding: UTF-8");
      header("Content-type: text/csv; charset=UTF-8");
      header("Content-Disposition: attachment; filename=" . $this->tmpfname . "");
      header("Content-Length: " . $file_size . "");
      header("Pragma: no-cache");
      header("Expires: 0");

      set_time_limit(0);
      fseek($file, $seek_start);

      while(!@feof($file)) {
        print(@fread($file, 1024*8));
        ob_flush();
        flush();
        if ( connection_status() != 0 ) {
          @fclose($file);
          exit;
        }
      }

    }

    function setOutput($string = '') {
      $this->output = $string;
    }

    // set the download filename
    function setFilename($filename = 'csvexport.csv') {
      $this->filename = $filename;
    }

    // set the CSV file
    function inisetCSV($optionally_enclosed = '', $fields_terminated = "\t", $lines_terminated = "\n") {
      $this->lines_terminated = $lines_terminated;
      $this->fields_terminated = $fields_terminated;
      $this->optionally_enclosed = $optionally_enclosed;
      $this->inistatus = true;
    }
  }


  /*
    Import from upload
    1. upload csv file
    2. parse csv
    3. get header
    4. slice file if need
    5. insert into data table
    6. delete uploaded files
  */

  class CSVImport {
    var $data;
    // Note fgetcsv return with "" value at the line end so I have to unset last array values
    function csv_to_array($filename = '', $delimiter = "\t") {
      if(!file_exists($filename) || !is_readable($filename))
        return FALSE;

      $header = NULL;
      $this->data = array();
      if (($handle = fopen($filename, 'r')) !== FALSE) {
        while (($row = fgetcsv($handle, 1000, $delimiter)) !== FALSE) {
          if (!$header) {
            unset($row[(count($row)-1)]);
            $header = $row;
          } else {
            unset($row[(count($row)-1)]);
            $this->data[] = array_combine($header, $row);
          }
        }
        fclose($handle);
      }

      return true;
    }

    function get_data() {
      return $this->data;
    }
  }
?>

:blink:
osCommerce based shop owner with minimal design and focused on background works. When the less is more.
Email managment with tracking pixel, package managment for shipping, stock management, warehouse managment with bar code reader, parcel shops management on 3000 pickup points without local store.

Share this post


Link to post
Share on other sites

@@altoid

Which SEO urls addons You have? Chemos's? 

Did You have any problems after installing this addon?

I have Chemos's SEO urls and product_info.php page I can see only with Add cPath to product URLs? option enabled.

Share this post


Link to post
Share on other sites

:thumbsup:

 

The next question is what should be the message?

 

Can the message stack be put into a language file, then let the shop owners modify that do their needs?

 

Also, will the message stack only show for redirected products and categories?  But not a 404 or 410 because that's a different situation.


I am not a professional webmaster or PHP coder by background or training but I will try to help as best I can.

I remember what it was like when I first started with osC. It can be overwhelming.

However, I strongly recommend considering hiring a professional for extensive site modifications, site cleaning, etc.

There are several good pros here on osCommerce. Look around, you'll figure out who they are.

Share this post


Link to post
Share on other sites

@@altoid

Which SEO urls addons You have? Chemos's? 

Did You have any problems after installing this addon?

I have Chemos's SEO urls and product_info.php page I can see only with Add cPath to product URLs? option enabled.

 

I am currently using Chemo's version.  I've had not problems directly with the url redirects related to that as far as I have observed and have been using url redirects for a long time, since it was in the beta version.

 

Checking my configuration for SEO URLS all options/setting look to be there.


I am not a professional webmaster or PHP coder by background or training but I will try to help as best I can.

I remember what it was like when I first started with osC. It can be overwhelming.

However, I strongly recommend considering hiring a professional for extensive site modifications, site cleaning, etc.

There are several good pros here on osCommerce. Look around, you'll figure out who they are.

Share this post


Link to post
Share on other sites

Can the message stack be put into a language file, then let the shop owners modify that do their needs?

Yes

 

Also, will the message stack only show for redirected products and categories?

 

Yes

 

Also, will the message stack only show for redirected products and categories? But not a 404 or 410 because that's a different situation.

 

There are redirections and header responses. USU 5 give 404 without any hasitation if products_id is not found from application_top so the product_info.php breaks in the first line. We dont have any possibiity to do something for 404/410 evens when URL redirection modul should be overtaken USU 5's classes.

 

I dont see any good fast solution without cache because all server request should be analyse before display something. V2.4 would be better with PDO cache for this problem

 

A simple array solution could be good from ini files (in v2.3) to do better 404/410 pages.

 

If no URL SEO than URL redirection could work with 404 or 410 responses. :(

 

There are two way. First we should rewrite URL SEO functions/classes with enable/disable URL SEO redirections in some cases or we should built in later the URL redirection into URL SEO secondly. :wacko:

 

 

 

I'd prefer that products_id and cPath or every params should be validated firstly in the codebase (like another parameter as language_id) and secondly URL SEO or Redirections could be use the validation informations. Its a dream of next versions.


:blink:
osCommerce based shop owner with minimal design and focused on background works. When the less is more.
Email managment with tracking pixel, package managment for shipping, stock management, warehouse managment with bar code reader, parcel shops management on 3000 pickup points without local store.

Share this post


Link to post
Share on other sites

now i cant edit the file, there is no  delimiter

attachicon.gifexcel.JPG

@@altoid

I have just rewrited the csvExpImp for better compatibility

 

Here is

very usefull for all excell users.

when you edited the file save into CSV (MS-DOS) mode!

 

Well, the new compatibility mode should be CSV (comma-separated values) and double qouted strings as phpMyAdmin do the same by default.

 

<?php
/*
  Copyright by Gergely Tóth http://oscom.hu

  v1.2b

  Export from query
  1. parse query
  2. get header fields
  3. run query and save results into temporary csv file
  4. download if need
  5. delete temporary file
*/

  define('FS_OUTPUT_PATH', '');

  class export2csv {
    // public variables
    var $filename,
        $lines_terminated,
        $fields_terminated,
        $optionally_enclosed,
        $output,
        $sql_result,
        $tmpfname = '';
    var $inistatus = false;

    // run the export
    //$query could be sql string or object results
    function downloadCsv($query = Null) {

      // default init call from built in $this->inisetCSV() function
      if (!$this->inisatus) {
        $this->inisetCSV();
      }

      if (!$this->filename) {
        $this->setFilename();
      }

      if (!is_object($query)) {
        $this->getResult($query);
      }

      $this->buildDatasheet($this->sql_result);
      $this->downloadFile();
      unlink(FS_OUTPUT_PATH . $this->tmpfname);

    }

    function getResult($query) {
      $this->sql_result = tep_db_query($query);
    }

    function buildHeader($sql_result) {
      // Get The Field Name from query
      while ( $columns = tep_db_fetch_fields($sql_result) ) {
        $this->output .= $columns->name . $this->fields_terminated;
      }
      $this->output = substr($this->output, 0, -(strlen($this->fields_terminated)));
      $this->output .= $this->lines_terminated;
    }

    function buildDatasheet($sql_result) {
      // init
      $this->tmpfname = strftime('%Y%m%d-%H%M%S') . '.csv';
      $fp = fopen(FS_OUTPUT_PATH . $this->tmpfname, "a+");

      // reset output and build csv header line
      $this->setOutput();
      $this->buildHeader($sql_result);

      fwrite($fp, $this->output);

      // Get Records from the query
      while ($row = tep_db_fetch_array($sql_result)) {
        fputcsv($fp, $row, $this->fields_terminated, $this->optionally_enclosed);
      }

      fclose($fp);
    }

    function downloadFile() {
      // Download the file

      $file_size  = filesize(FS_OUTPUT_PATH . $this->tmpfname);
      $file = @fopen(FS_OUTPUT_PATH . $this->tmpfname,"rb");

      header("Content-Encoding: UTF-8");
      header("Content-type: text/csv; charset=UTF-8");
      header("Content-Disposition: attachment; filename=" . $this->tmpfname . "");
      header("Content-Length: " . $file_size . "");
      header("Pragma: no-cache");
      header("Expires: 0");

      set_time_limit(0);
      fseek($file, $seek_start);

      while(!@feof($file)) {
        print(@fread($file, 1024*8));
        ob_flush();
        flush();
        if ( connection_status() != 0 ) {
          @fclose($file);
          exit;
        }
      }

    }

    function setOutput($string = '') {
      $this->output = $string;
    }

    // set the download filename
    function setFilename($filename = 'csvexport.csv') {
      $this->filename = $filename;
    }

    // set the CSV file
    function inisetCSV($optionally_enclosed = '"', $fields_terminated = ",", $lines_terminated = "\n") {
      $this->lines_terminated = $lines_terminated;
      $this->fields_terminated = $fields_terminated;
      $this->optionally_enclosed = $optionally_enclosed;
      $this->inistatus = true;
    }
  }


  /*
    Import from upload
    1. upload csv file
    2. parse csv
    3. get header
    4. slice file if need
    5. insert into data table
    6. delete uploaded files
  */

  class CSVImport {
    var $data;

    function csv_to_array($filename = '', $delimiter = ",") {
      if(!file_exists($filename) || !is_readable($filename))
        return false;

      $header = null;
      $this->data = array();
      if (($handle = fopen($filename, 'r')) !== false) {
        while (($row = fgetcsv($handle, 1000, $delimiter)) !== false) {
          if (!$header) {
            $header = $row;
          } else {
            $this->data[] = array_combine($header, $row);
          }
        }
        fclose($handle);
      }

      return true;
    }

    function get_data() {
      return $this->data;
    }
  }
?>

:blink:
osCommerce based shop owner with minimal design and focused on background works. When the less is more.
Email managment with tracking pixel, package managment for shipping, stock management, warehouse managment with bar code reader, parcel shops management on 3000 pickup points without local store.

Share this post


Link to post
Share on other sites

I will upload the latest version this week and work with the csv download / upload to see how that goes.  Thanks

 

 

@@altoid

I have just rewrited the csvExpImp for better compatibility

Here is

very usefull for all excell users.
when you edited the file save into CSV (MS-DOS) mode!

 

Well, the new compatibility mode should be CSV (comma-separated values) and double qouted strings as phpMyAdmin do the same by default.
 


I am not a professional webmaster or PHP coder by background or training but I will try to help as best I can.

I remember what it was like when I first started with osC. It can be overwhelming.

However, I strongly recommend considering hiring a professional for extensive site modifications, site cleaning, etc.

There are several good pros here on osCommerce. Look around, you'll figure out who they are.

Share this post


Link to post
Share on other sites

Just as an FYI, here's an example of what the log is capturing from URL redirects regarding products.

 

post-231701-0-35082900-1434277056_thumb.jpg

 

I am seeing a lot of these.

 

I'm pretty sure it's not customers, but whatever the source I have no idea what the products were in that they were probably deleted long ago.

 

So I decided how to handle these is a 301 redirect to the home page, or / for the new url on the url redirects page.

Edited by altoid

I am not a professional webmaster or PHP coder by background or training but I will try to help as best I can.

I remember what it was like when I first started with osC. It can be overwhelming.

However, I strongly recommend considering hiring a professional for extensive site modifications, site cleaning, etc.

There are several good pros here on osCommerce. Look around, you'll figure out who they are.

Share this post


Link to post
Share on other sites

did you see the online help?


:blink:
osCommerce based shop owner with minimal design and focused on background works. When the less is more.
Email managment with tracking pixel, package managment for shipping, stock management, warehouse managment with bar code reader, parcel shops management on 3000 pickup points without local store.

Share this post


Link to post
Share on other sites

I did now that you mentioned it.  When using the beta, I don't think that was set up yet and I never tried it.  But I see what you did with specific recommendations for specific issues.  Very nice.   :thumbsup:


I am not a professional webmaster or PHP coder by background or training but I will try to help as best I can.

I remember what it was like when I first started with osC. It can be overwhelming.

However, I strongly recommend considering hiring a professional for extensive site modifications, site cleaning, etc.

There are several good pros here on osCommerce. Look around, you'll figure out who they are.

Share this post


Link to post
Share on other sites

I updated my url redirects add on to the latest and then downloaded the file.  It was delimited by semicolon, so that's how I imported it.  It worked fine, putting the fields into columns in Excel.

 

I then saved the file as csv.  Is that the correct format for uploading?

 

Also, when uploading, is the data processed as an update query?  Meaning if I have only 10 records I want to update, can I upload just those?  Or do I have to upload the entire file, with changes to just the 10 records?

 

I don't want to upload just 10 records and lose thousands already in place.

 

Thanks


I am not a professional webmaster or PHP coder by background or training but I will try to help as best I can.

I remember what it was like when I first started with osC. It can be overwhelming.

However, I strongly recommend considering hiring a professional for extensive site modifications, site cleaning, etc.

There are several good pros here on osCommerce. Look around, you'll figure out who they are.

Share this post


Link to post
Share on other sites

Doing some SSL online help testing and got this:

 

Parse error: syntax error, unexpected ')', expecting :: (T_PAAMAYIM_NEKUDOTAYIM) in /web/oscom/help/includes/OSC/OM/OSCOM.php on line 63


I am not a professional webmaster or PHP coder by background or training but I will try to help as best I can.

I remember what it was like when I first started with osC. It can be overwhelming.

However, I strongly recommend considering hiring a professional for extensive site modifications, site cleaning, etc.

There are several good pros here on osCommerce. Look around, you'll figure out who they are.

Share this post


Link to post
Share on other sites

 When I go Google webmasters and other statistic page, I see blank page with error 500 when I click broken link. Is this correct now?

Share this post


Link to post
Share on other sites

Doing some SSL online help testing and got this:

 

Parse error: syntax error, unexpected ')', expecting :: (T_PAAMAYIM_NEKUDOTAYIM) in /web/oscom/help/includes/OSC/OM/OSCOM.php on line 63

Yes its correct PHP 5.4 is not recommended for v2.4 sites :thumbsup:  server updated now

 

 


:blink:
osCommerce based shop owner with minimal design and focused on background works. When the less is more.
Email managment with tracking pixel, package managment for shipping, stock management, warehouse managment with bar code reader, parcel shops management on 3000 pickup points without local store.

Share this post


Link to post
Share on other sites

I updated my url redirects add on to the latest and then downloaded the file.  It was delimited by semicolon, so that's how I imported it.  It worked fine, putting the fields into columns in Excel.

 

I then saved the file as csv.  Is that the correct format for uploading?

 

Also, when uploading, is the data processed as an update query?  Meaning if I have only 10 records I want to update, can I upload just those?  Or do I have to upload the entire file, with changes to just the 10 records?

 

I don't want to upload just 10 records and lose thousands already in place.

 

Thanks

 

Deletion is allowed on admin site only. CSS import update or insert only.


:blink:
osCommerce based shop owner with minimal design and focused on background works. When the less is more.
Email managment with tracking pixel, package managment for shipping, stock management, warehouse managment with bar code reader, parcel shops management on 3000 pickup points without local store.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×