[osCommerce] Rewrite rule for custom page not redirecting

Custom URLs and redirections.
shotputty
Follower
Posts: 46
Joined: Tue May 11, 2010 3:28 pm

Re: [osCommerce] Rewrite rule for custom page not redirectin

Postby shotputty » Tue Jun 15, 2010 4:42 am

I will purchase another license (new site) today and will send you the ftp of that domain. If you can solve the static pages on that site I can use that generic solution on my other site.
The reason is i can't have testing too much on a very busy domain. If this will work you migth help out many more and make this license much more interesting for OScommerce user.

I will PM soon. ;)

shotputty
Follower
Posts: 46
Joined: Tue May 11, 2010 3:28 pm

Re: [osCommerce] Rewrite rule for custom page not redirectin

Postby shotputty » Thu Jun 17, 2010 1:09 am

I see some efforts have been made in .htaccess. I've been told no custom MSU licenses are possible.

If you can't get it to work, what are my options?

inveo
Inveo Support
Posts: 1285
Joined: Sat Feb 02, 2008 12:07 pm
Contact:

Re: [osCommerce] Rewrite rule for custom page not redirectin

Postby inveo » Thu Jun 17, 2010 8:49 am

Customized MSU are no longer provided.

Regarding your requested changes to .htaccess file, we are working on it.

shotputty
Follower
Posts: 46
Joined: Tue May 11, 2010 3:28 pm

Re: [osCommerce] Rewrite rule for custom page not redirectin

Postby shotputty » Mon Jun 28, 2010 1:48 am

I've tried some custom rules myself for some time now, can't seem to get anything to work.

I know this rule makes the pages work (but not redirect):

Code: Select all

RewriteRule ^([a-z]{2})/all-products$ all_products.php?language=$1 [L,QSA]


Then I thought if I redirect the non-seo pages to that SEO page I'm done, but then I get eternal loops.

http://www.powersupplements.de/all_prod ... anguage=en redirects to http://www.powersupplements.de/en/all-products which is rewritten internally like it should to the http://www.powersupplements.de/all_products.php page which is then redirected to the nice SEO page and so on....

Is it possible to use $_SERVER['REQUEST_URI'] (in .htaccess) as a way to stop the redirect when it lands on the SEO page? :roll:

If you login with ftp there's no need to change permissions on .htaccess, it isn't being overwritten by MSU whatsoever. :|

shotputty
Follower
Posts: 46
Joined: Tue May 11, 2010 3:28 pm

Re: [osCommerce] Rewrite rule for custom page not redirectin

Postby shotputty » Wed Jun 30, 2010 5:38 am

I made a MOD which I will post here. It works for custom pages, you only need to change the tep_href_link function in your includes/html_output.php file, and add 1 line of code per new page in your .htaccess file.

First backup!!
Then replace from
// The HTML href link wrapper function
until
return $link ; }


with this code:

Code: Select all

  ////
// The HTML href link wrapper function
  function tep_href_link($page = '', $parameters = '', $connection = 'NONSSL', $add_session_id = true, $search_engine_safe = true) {
    global $request_type, $session_started, $SID, $unCurrentLang  ;

    if (!tep_not_null($page)) {
      die('</td></tr></table></td></tr></table><br><br><font color="#ff0000"><b>Error!</b></font><br><br><b>Unable to determine the page link!<br><br>');
    }

    if ($connection == 'NONSSL') {
     $link = HTTP_SERVER . DIR_WS_HTTP_CATALOG ;
     
     
    } elseif ($connection == 'SSL') {
      if (ENABLE_SSL == true) {
        $link = HTTPS_SERVER . DIR_WS_HTTPS_CATALOG;
      } else {
        $link = HTTP_SERVER . DIR_WS_HTTP_CATALOG;
      }
    } else {
      die('</td></tr></table></td></tr></table><br><br><font color="#ff0000"><b>Error!</b></font><br><br><b>Unable to determine connection method on a link!<br><br>Known methods: NONSSL SSL</b><br><br>');
    }


//Modification for Magic Seo Url custom pages addition for OScommerce

//for each additional page add a line with a subsequent number like: $customepages_non_seo[following number] = "your_new__non_seo_name_page.php" ;
$customepages_non_seo[0] = "all_products.php" ;
$customepages_non_seo[1] = "some_products.php" ;

//for each additional page add a line with the SEO NAME YOU WANT (!) with a subsequent number like: $customepages_yes_seo[corresponding number] = "your-seo-name-for-that-page-without-extension-if-you-like" ;
$customepages_yes_seo[0] = "all-products" ;
$customepages_yes_seo[1] = "some-products" ;

//add each new page in includes/filenames.php like any other page (example): define('FILENAME_SOME_PRODUCTS', 'some_products.php');
//add catalog/your_new_file.php and includes/languages/your_new_file.php (this is basic OScommerce knowledge for adding pages)

//place 1 rule per new page in .htaccess like this:
// RewriteRule ^([a-z]{2})/all-products$ all_products.php?language=$1 [L,QSA]
//change accordingly to your own names for each line you add

if (tep_not_null($parameters)) {

switch ($page) {

    case in_array($page, $customepages_non_seo) :
       $seokey = array_search($page, $customepages_non_seo); // $seokey = ''number corresponding to the page;
       $parts = explode("=",$parameters);  //break the string up around the "=" character in $mystring
 
           if ($parameters == 'language=' . $parts['1']) {
             $link .= $parts['1'] . '/' . $customepages_yes_seo[$seokey] ;
           } else {
             $link .= $unCurrentLang . '/' . $customepages_yes_seo[$seokey] . '?' . tep_output_string($parameters);
             $separator = '&';
           }
    break;




  //original code
   default:
   $link .= $page . '?' . tep_output_string($parameters);
   $separator = '&';
//end original code
}

} else {

switch ($page) {

    case in_array($page, $customepages_non_seo) :
    $seokey = array_search($page, $customepages_non_seo); // $seokey = ''number corresponding to the page;
     $link .= $unCurrentLang  . '/' . $customepages_yes_seo[$seokey] ;
     $separator = '?';
   break;



 default:
 //original code
 
  $link .= $page ;
  $separator = '?';
//end original code
}}
//end of modification for Magic Se0 Url









    while ( (substr($link, -1) == '&') || (substr($link, -1) == '?') ) $link = substr($link, 0, -1);

// Add the session ID when moving from different HTTP and HTTPS servers, or when SID is defined
    if ( ($add_session_id == true) && ($session_started == true) && (SESSION_FORCE_COOKIE_USE == 'False') ) {
      if (tep_not_null($SID)) {
        $_sid = $SID;
      } elseif ( ( ($request_type == 'NONSSL') && ($connection == 'SSL') && (ENABLE_SSL == true) ) || ( ($request_type == 'SSL') && ($connection == 'NONSSL') ) ) {
        if (HTTP_COOKIE_DOMAIN != HTTPS_COOKIE_DOMAIN) {
          $_sid = tep_session_name() . '=' . tep_session_id();
        }
      }
    }

    if ( (SEARCH_ENGINE_FRIENDLY_URLS == 'true') && ($search_engine_safe == true) ) {
      while (strstr($link, '&&')) $link = str_replace('&&', '&', $link);

      $link = str_replace('?', '/', $link);
      $link = str_replace('&', '/', $link);
      $link = str_replace('=', '/', $link);

      $separator = '?';
    }

    if (isset($_sid)) {
      $link .= $separator . tep_output_string($_sid);
    }

    return $link ;
  }


add each new page in includes/filenames.php like any other page (example): define('FILENAME_SOME_PRODUCTS', 'some_products.php');
add catalog/your_new_file.php and includes/languages/your_new_file.php (this is basic OScommerce knowledge for adding pages)

place 1 rule per new page in .htaccess like this:
RewriteRule ^([a-z]{2})/all-products$ all_products.php?language=$1 [L,QSA]
change accordingly to your own names for each line you add

IMPORTANT, this code (above) contains two example filenames, you need to adjust them or add new ones according to your own pagenames!!

IMPORTANT 2: this code is setup for multilanguage, it will add the /en or /fr or /de between your url and your filename.


ranton
Posts: 1
Joined: Thu Sep 16, 2010 7:45 am

Re: [osCommerce] Rewrite rule for custom page not redirectin

Postby ranton » Sat Sep 18, 2010 2:38 pm

Thid mod works also if the page has parameters? Like:

http://www.domain.com/shop/categories.php?cPath=2

Thank You

shotputty
Follower
Posts: 46
Joined: Tue May 11, 2010 3:28 pm

Re: [osCommerce] Rewrite rule for custom page not redirectin

Postby shotputty » Wed Sep 22, 2010 5:28 am

This MOD works only for static pages. For dynamic pages I'm waiting for a reply from the admin (See my other post in this section).