Jump to content
spidometrs

[CONTRIBUTION] Ultimate SEO URLs v2.1 - by Chemo

Recommended Posts

Okay, i've fixed this. In some places the first parameter $page of tep_href_link was being supplied including the catalog subfolder. So i've tweaked tep_href_link to strip this out, and it now works. But thats a bit hacky so if you know of the root cause and proper fix for it, that would be appreciated.

Share this post


Link to post
Share on other sites

There's no way for me to see what the proper fix is at this point and from here but I can say that you shouldn't have to edit existing functions. My guess is that either your configure file is not setup correctly or the links are coded incorrectly.

Share this post


Link to post
Share on other sites

In the SEO_URL_INSTALLER function (line 257) in seo.class.php there are five instances where the configuration_id is set to '' instead of NULL.

 

Not a problem for everyone but in some mysql configurations this causes a reinstall on every single page.

It keeps trying to load the missing configurations!

 

'QUERY' => "INSERT INTO `".TABLE_CONFIGURATION."` VALUES ('',   .......
 

should be (5 places)

 

'QUERY' => "INSERT INTO `".TABLE_CONFIGURATION."` VALUES (NULL,  .......

 

Many thanks for the great support.

Share this post


Link to post
Share on other sites

If you are using one of my versions, you need to update your installation since that code was changed years ago.

Share this post


Link to post
Share on other sites

 

If you are using one of my versions, you need to update your installation since that code was changed years ago.

Hi Jack

I'm installing the latest 2-2-2d-14a, released by roaddoctor in January.

I had a browse through the history and it first occured in your release 2-2-2d-6 back in 2010.

Most of them are fine, just those odd 5.

 

Its obviously not causing to many problems, but worth changing on the next release.

 

Many thanks

Share this post


Link to post
Share on other sites

I`ve been looking at some duplicate content on google that should have been redirected. I was also curious about why sub-categories always send a redirect for the parent before the correct one.
 
This lead me to the check_direct function in seo_class.php and I'm amazed that it works at all.There are simple mistakes like:
$path = substr(string, start, end)   instead of   $path = substr(string, start, length);
and
substr_replace(string,newstring, start, strlen(start))   instead of   substr_replace(string,newstring, start, strlen(oldstring))
 
This is what I ended up with, but it needs tidying up and more thorough testing. I havent tried the category_id=0 section.

 

        function check_redirect(){
                $this->need_redirect = false;
                $this->path_info = is_numeric(strpos(ltrim(getenv('PATH_INFO'), '/') , '/')) ? ltrim(getenv('PATH_INFO'), '/') : NULL;
                $this->uri = ltrim( basename($_SERVER['REQUEST_URI']), '/' );
                $this->real_uri = ltrim( basename($_SERVER['SCRIPT_NAME']) . '?' . $_SERVER['QUERY_STRING'], '/' );
                $this->uri_parsed = $this->not_null( $this->path_info )
                                                                ?        parse_url(basename($_SERVER['SCRIPT_NAME']) . '?' . $this->parse_path($this->path_info) )
                                                                :        parse_url(basename($_SERVER['REQUEST_URI']));                        
                $this->attributes['SEO_REDIRECT']['PATH_INFO'] = $this->path_info;                        
                $this->attributes['SEO_REDIRECT']['URI'] = $this->uri;
                $this->attributes['SEO_REDIRECT']['REAL_URI'] = $this->real_uri;                        
                $this->attributes['SEO_REDIRECT']['URI_PARSED'] = $this->uri_parsed;    

 
                /**** redirect child path to full path - i.e., -c-3782.html to -c-28_3782.html, when applicable ****/
                if (strpos($this->attributes['SEO_REDIRECT']['URI_PARSED']['path'], '.html') !== FALSE) {
                    $u1 = $this->attributes['SEO_REDIRECT']['URI_PARSED']['path'];
               
                    if (($pStart = strrpos($u1, "-c-")) !== FALSE) {  //using strrpos - might help when -c- is used in the name by mistake
                       if (($pStop = strpos($u1, ".html")) !== FALSE) {
                          //$path = substr($u1, $pStart, $pStop); // wrong syntax         
                            $actualID = substr($u1, $pStart + 3, $pStop - $pStart - 3);
                          //if (($pStart = strpos($path, "-")) !== FALSE) {
                              //if (($pStop = strpos($path, ".html")) !== FALSE) {
                                  /**** GET THE ID's AND PATH's ****/
                                  //$actualID = substr($path, $pStart + 3, $pStop - 3); // wrong syntax
                                  //$fullID = $this->get_full_cPath($actualID, $actualID);  
                                  
                                  // get_full_cPath only returns the correct fullID if given the child on its own
                                  // but it always returns the child (by reference), so we can run it twice
                                  $fullID = $this->get_full_cPath($actualID, $childID);
                                  $fullID = $this->get_full_cPath($childID, $childID);
                                  $actualPath = $actualID . '.html';        //save a few instructions
                                  
                                  /**** REPLACE THE PARTIAL ID IN THE URL's WITH THE FULL ONE ****/
                                  $idPos = strpos($this->attributes['SEO_REDIRECT']['REAL_URI'], $actualID);            
                                //$this->attributes['SEO_REDIRECT']['REAL_URI'] = substr_replace($this->attributes['SEO_REDIRECT']['REAL_URI'], $fullID, $idPos, strlen($idPos));
                                  $this->attributes['SEO_REDIRECT']['REAL_URI'] = substr_replace($this->attributes['SEO_REDIRECT']['REAL_URI'], $fullID, $idPos, strlen($actualID));
                                  $idPos = strpos($this->attributes['SEO_REDIRECT']['URI'], $actualID);  
                                //$this->attributes['SEO_REDIRECT']['URI'] = substr_replace($this->attributes['SEO_REDIRECT']['URI'], $fullID, $idPos, strlen($idPos));
                                  $this->attributes['SEO_REDIRECT']['URI'] = substr_replace($this->attributes['SEO_REDIRECT']['URI'], $fullID, $idPos, strlen($actualID));
                                  if (strpos($this->attributes['SEO_REDIRECT']['URI_PARSED']['path'], '-c-'.$actualPath) !== FALSE) { //this is the actual url
                                    //if ($fullID != $actualID && strpos($fullID.'.html', $actualPath) !== FALSE) { //enteed url is child of full path
                                      if ($fullID != $actualID) { //enteed url is child of full path
                                          $url = $this->make_url($page, $this->get_category_name($actualID), 'cPath', $fullID, '.html');
                                          $this->uri_parsed['path'] = $url; //reset the url
                                          $this->need_redirect = true;
                                          $this->is_seopage = true;  
                                          if ( $this->need_redirect && $this->is_seopage && $this->attributes['USE_SEO_REDIRECT'] == 'true') $this->do_redirect();
                                      }
                                  }  
                              //}  
                          //}
                       }
                    }
                }
        
        
                /**** redirect for special case of cat ID = 0 ****/
                if (strpos($this->attributes['SEO_REDIRECT']['URI_PARSED']['path'], '.html') !== FALSE) {
                    $u1 = $this->attributes['SEO_REDIRECT']['URI_PARSED']['path'];
               
                    if (($pStart = strpos($u1, "-c-")) !== FALSE) {         //start isolating the ID - only for categories
                       if (($pStop = strpos($u1, ".html")) !== FALSE) {
                          //$path = substr($u1, $pStart, $pStop + 5);             //will be something like -c-34.html

                          //if (($pStart = strpos($path, "-")) !== FALSE) {   //isolate to the number
                              //if (($pStop = strpos($path, ".html")) !== FALSE) {
                              
                                  /**** GET THE ID's AND PATH's ****/
                                  //$actualID = substr($path, $pStart + 3, $pStop - 3); //will be something like 34
                                    $actualID = substr($u1, $pStart + 3, $pStop - $pStart - 3);
                                  if ($actualID == 0) {
                                      $actualPath = $actualID . '.html';        //save a few instructions
                                      
                                      /**** REPLACE THE PARTIAL ID IN THE URL's WITH THE FULL ONE ****/
                                      $this->attributes['SEO_REDIRECT']['REAL_URI'] = 'index.php';
                                      $this->attributes['SEO_REDIRECT']['URI'] = '';
                                      
                                      if (strpos($this->attributes['SEO_REDIRECT']['URI_PARSED']['path'], '-c-'.$actualPath) !== FALSE) { //this is the actual url
                                          if (0 == $actualID && strpos($actualID.'.html', $actualPath) !== FALSE) { //enteed url is child of full path
                                              $url = 'index.php';
                                              $this->uri_parsed['path'] = $url; //reset the url
                                              $this->need_redirect = true;
                                              $this->is_seopage = true;  
                                              if ( $this->need_redirect && $this->is_seopage && $this->attributes['USE_SEO_REDIRECT'] == 'true') {
                                                  header("HTTP/1.0 404 not found");
                                                  header("Location: $url"); // redirect...bye bye  
                                              }
                                          }
                                      }  
                                  }
                              //}  
                          //}
                       }
                    }
                }           

                      
                $this->need_redirect();
                $this->check_seo_page();  
                if ( $this->need_redirect && $this->is_seopage && $this->attributes['USE_SEO_REDIRECT'] == 'true') $this->do_redirect();                        
        } # end function
 

 

Share this post


Link to post
Share on other sites

@@pchelpwebshop As mentioned, you are not using one of my versions so I can't comment on what you posted since that is not the case in my version, at least that I can see.

 

There also isn't a way to identify duplicate content on google. I suspect you are getting confused by duplicate tags, which is entirely different. If you are concerned about two paths to the same page, which is not seen as duplicate content, you can install my Header Tags SEO and enable the option to prevent that.

 

But I do want to warn others to be careful of applying changes like this. The addon has worked for years so such a change is almost certainly not needed and should not be blindly made. I'm not saying the posted code is wrong in any way but that it only should be made if really needed.

Share this post


Link to post
Share on other sites

@@Jack

Sloppy on my part. Yes I was talking about duplicate title tags and duplicate meta descriptions.for the categories.

Whilst I was correcting the code I tweeked it so that it redirects all incorrect category urls which I hope some may find useful.

Thank you for pointing out the Header Tags SEO.

 

The code in question dates back to 2010, but has been in every subsequent release. I agree that code should not be altered needlessly, and changes kept to a minimum. I feel discouraged from making any more posts.

 

I am about to start restructing some of my categories, which i can now do with the knowledge that the category redirects are comprehensive.

 

Many Thanks

Share this post


Link to post
Share on other sites

@@pchelpwebshop I apologize if you took my post personally. It was not meant that way. Please don't hesitate to post things. It is what this forum is all about. But I do suggest that if you are going to troubleshoot problems that you use recent versions. The code you mentioned is not in my version, at least that I can find, but you say it is in there so one of us is missing something.

Share this post


Link to post
Share on other sites

@@Jack_mcs

 

My site version is OSC 2.3.4bs. I use your latest version of this addon. For some reason, the manufacturer's name doesn't appear in the urls.

 

Where should I check?

 

Thanks

Share this post


Link to post
Share on other sites
Hi, I seem to have a minor problem with SEO URLs/session.php compatibility in v234bs? I’ll try to explain what I believe the problem is -
 
v234bs SEO URLs with ‘Force Cookie Use’ = true:
    Clear all cookies/browsing data
    Go to site
    Enter a Search Key and Search
    Enter a Search Key (same or different to first) and Search
 
Result:
    instead on being in advanced_search_result.php, index.php is loaded. Additionally an error is thrown from includes/classes/seo.class.php “undefined constant CHARSET - assumed 'CHARSET' On line 1824”.
 
Log entries (note the inclusion of osCsid?):
    “GET /advanced_search_result.php?keywords=creed&osCsid=b5lpc34dn9fchcgp043q188qr3 HTTP/1.1" 302 421 "http --/advanced_search_result.php?keywords=creed
    “GET /index.php HTTP/1.1" 200 5956 “http --/advanced_search_result.php?keywords=creed"
 
 
The problem also seems to occur with:
    Clear all cookies/browsing data
    Go to site
    Go to Product Listing (i.e. category list)
    Select Manufacturer from Product Listing filter
 
The problem only seems to happen once, everything appears OK subsequently.
 
Problem doesn’t seem to happen:
    with ‘Force Cookie Use’ = false
    using a v233 “sessions.php”
    on a clean v234bs with no SEO URLs
 
 
Many Thanks

 

Share this post


Link to post
Share on other sites
Hi, Further to my earlier query (#7144), in case it’s relevant -

 

    changing includes/functions/sessions.php

 

        in function tep_session_start()

            remove (SESSION_FORCE_COOKIE_USE == 'True') ||

        from lines 65 & 73 (maybe just 65 may be sufficient?)

 

seems to cure the problem

 

I don’t know if it is OK to make this change or if there are any other issues, obviously the code is there for a reason?

 

Is the issue to do with SEO URLs or v234bs sessions.php?

 

Many thanks

Share this post


Link to post
Share on other sites

My site version is OSC 2.3.4bs. I use your latest version of this addon. For some reason, the manufacturer's name doesn't appear in the urls.

There's a known problem in that version. Please find this line

WHERE manufacturers_id='".(int)$mID."' 

and change it to

WHERE m.manufacturers_id='".(int)$mID."'

Share this post


Link to post
Share on other sites

@@trier The code in this addon just uses the core code for that option so it sounds either this addon isn't installed correctly or there is something wrong in basic code (seems unlikely).

Share this post


Link to post
Share on other sites

@@Jack_mcs

 
Hi, Thank you for the reply, I appreciate it. Are you able to replicate the problem? (If it exists) it may be a session problem and not an SEO URL problem (i.e. there may be other instances where a first/second page submit redirects to index.php).
 
The full piece of code in tep_session_start() is -
 
    if ( isset($HTTP_GET_VARS[tep_session_name()]) ) {
      if ( (SESSION_FORCE_COOKIE_USE == 'True') || (preg_match('/^[a-zA-Z0-9,-]+$/', $HTTP_GET_VARS[tep_session_name()]) == false) ) {
        unset($HTTP_GET_VARS[tep_session_name()]);
        $sane_session_id = false;
      }
    }
 
 
The “(SESSION_FORCE_COOKIE_USE == 'True') || “ seems to cause the problem, I don’t believe it existed in previous incarnations of session.php, removing it cures the problem.
 
Should I raise the query again within the v2.4 support topic?
 
Many thanks

Share this post


Link to post
Share on other sites

I don't use, nor recommend, force cookies. I turned it on here for a quick test but don't see the problem, though that may be due to how I have my test environment setup. But, as far as I can tell, this isn't an issue with this addon. If possible, I suggest installing a non-BS version of oscommerce with this addon installed to see if the problem exists with it. If not, then it is a problem with the BS version. You should post the problem in the general forum.

Share this post


Link to post
Share on other sites

 

There's a known problem in that version. Please find this line

WHERE manufacturers_id='".(int)$mID."' 

and change it to

WHERE m.manufacturers_id='".(int)$mID."'

Thanks Jack! Works like a charm.

Share this post


Link to post
Share on other sites

I was having trouble with the number of concurrent database connections, I've rewritten the code to use standard oscommerce tep_db functions as it will allow me to further finetune/debug things.

When working on this, I was thinking these database round trips are rather silly most of the time, so I'm now working on caching the files.

 

I noticed that define statements are generated, and wondered why define constants and not arrays are used.

 

Is there a good reason for using defines over arrays to keep this cached data ?


KEEP CALM AND CARRY ON

I do not use the responsive bootstrap version since i coded my responsive version earlier, but i have bought every 28d of code package to support burts effort and keep this forum alive (albeit more like on life support).

So if you are still here ? What are you waiting for ?!

 

Find the most frequent unique errors to fix:

grep "PHP" php_error_log.txt | sed "s/^.* PHP/PHP/g" |grep "line" |sort | uniq -c | sort -r > counterrors.txt

Share this post


Link to post
Share on other sites

@@bruyndoncx My guess is that it was coded that way for speed since using defined is a little faster than isset. But the biggest problem with the cache system is that it was coded to include all of the cached values in one command. This doesn't matter much on sites with a small number of products but cache can't used when there are too many products because it causes a memory failure. I have it on my list of things to do to rewrite that but it would be much better, for me, if you wanted to tackle it. :)

Share this post


Link to post
Share on other sites

@@Jack_mcs

so the cache should be for active products (products_status =: 1) only, and fetch the data adhoc (when needed) for non-active products ?

 

I was running into memory issues with the define statements (about 18000 products of which 7000 active)

 

I'll continue to work on it so that it works like the other caching I have, but it is not standard.

My cache uses apcu memorycache now (version of APC usercache for php 5.4/5.5) , then fallsback to a file cache (modified oscommerce cachemanager), and then only accessing the database.

 

I'll share my work, you can see if it helps or not

Edited by bruyndoncx

KEEP CALM AND CARRY ON

I do not use the responsive bootstrap version since i coded my responsive version earlier, but i have bought every 28d of code package to support burts effort and keep this forum alive (albeit more like on life support).

So if you are still here ? What are you waiting for ?!

 

Find the most frequent unique errors to fix:

grep "PHP" php_error_log.txt | sed "s/^.* PHP/PHP/g" |grep "line" |sort | uniq -c | sort -r > counterrors.txt

Share this post


Link to post
Share on other sites

Usually non-active products don't need to be cached but I have worked on a few shop that have code changes where inactive products still show since they will become available again. But the cache entry should only be made when the link is created so if the code creates a link, whatever the status, a cache entry should be made.

 

APC isn't common in shops but as long the fallback works, that won't be an issue. At least as long as the overhead caused by that switching doesn't cause much of a slow down. I wouldn't expect it to but it should be tested just in case. 

Share this post


Link to post
Share on other sites

Dears,

rewrites aren't supported on Windows servers. These rewrites for Linux mod_rewrite module. would you please help to provide the rewrites for Windows 'URL Rewrite' asap?

 

Thanks & Best Regards,

Sunrise99

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

×