Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

URLs Being created with Parameters .. Cannot get rid of them


NuDreamer

Recommended Posts

Hi Guys, this may be a little lengthy, but I'm hoping it makes sense to someone, and we can find a solution. The addon I am using for my URL structure is Ultimate SEO Urls. (http://addons.oscommerce.com/info/2823)

 

First things first, I am running osCommerce 2.3.4 Bootstrap. I recently upgraded my website from RCA 2.2. This process, included me moving my website from the /catalog/ directory, where my shop had sat before (sitename.com/catalog) into the root directory. Now shop is accessed at sitename.com. So, when I launched the site, I wrote redirects for every category page and product page. From /catalog/ to /. Example:

Redirect 301 catalog/product-name-p-1.html http://www.sitename.com/product-name-p-1.html

 

However, something about that just flat didn't work. I launched the site, and the next day I started seeing some unusual urls. So I went and tested an old /catalog/ url to see if it was forwarding correctly. The forwarded URL looked like the following: sitename.com/product-name-p-1.html?products_id=1 .. which made NO sense. Why the heck was it adding the ?products_id after the URL? There was no reason for that. To make matters worse.. Google found those URLs within a day of my site change, and instantly gave me duplicate meta and content warnings, because it was seeing

 

product-name-p-1.html?products_id=1

product-name-p-1.html

 

as having the same content. Which.. they do of course. So I changed up my redirect. I rewrite all my redirects as such:

RewriteRule ^catalogproduct-name-p-1.html$  /product-name-p-1.html [L,R=301]

 

This fixed the parameter being added to the URL when you type in the old /catalog/ url and get the redirect. HOWEVER, if I go to my site, and type in manually a URL such as this: product-name-p-1.html?products_id=1 ... I get a perfectly valid page. WITH that parameter. The only positive thing about it.. Is that the canonical at the very least remains correct. No matter what parameters are in the URL.

 

I need some way, some how.. to either redirect those URLs to the version without the ?products_id=1 so they drop out of the index.. or even get a piece of code that says if full url ends with ?products_id=# then implement a noindex tag.
 

I have no idea where to even go from here, and I'm hoping you guys can give me some insight and help to get this figured out. Thanks! If you need the actual site name, or a copy of the htaccess file where all the redirects are, let me know and I'll PM you a copy.

Link to comment
Share on other sites

@@NuDreamer Your redirect code should be using the standard format - product_info.php?... - not the rewritten one. There isn't any code in place to stop a parameter from being added to the end of the url since that is acceptable in some situations. I think the best solution would be to add code to the application_top file to check url's for the extra parameter and then return a 301 to the correct url.

Support Links:

For Hire: Contact me for anything you need help with for your shop: upgrading, hosting, repairs, code written, etc.

All of My Addons

Get the latest versions of my addons

Recommended SEO Addons

Link to comment
Share on other sites

@@NuDreamer I haven't tested it but I think it will work. In the includes/application_top.php file, find this line

require(DIR_WS_LANGUAGES . $language . '.php');

and add this below it:

  $pos = strpos($_SERVER['REQUEST_URI'], "html?products_id=");
  if ($pos !== FALSE ) {  
      $badpart = $pos + 4;  //points to part starting with ?  
      $lgth = strlen(substr($_SERVER['REQUEST_URI'], $badpart)); //length from ? to end 
      $location = substr($_SERVER['REQUEST_URI'], 0 , -($lgth));
      $location = tep_href_link($location);
      header("HTTP/1.0 301 Moved Permanently");
      header("Location: $location"); 
  }

Support Links:

For Hire: Contact me for anything you need help with for your shop: upgrading, hosting, repairs, code written, etc.

All of My Addons

Get the latest versions of my addons

Recommended SEO Addons

Link to comment
Share on other sites

 

@@NuDreamer I haven't tested it but I think it will work. In the includes/application_top.php file, find this line

require(DIR_WS_LANGUAGES . $language . '.php');

and add this below it:

  $pos = strpos($_SERVER['REQUEST_URI'], "html?products_id=");
  if ($pos !== FALSE ) {  
      $badpart = $pos + 4;  //points to part starting with ?  
      $lgth = strlen(substr($_SERVER['REQUEST_URI'], $badpart)); //length from ? to end 
      $location = substr($_SERVER['REQUEST_URI'], 0 , -($lgth));
      $location = tep_href_link($location);
      header("HTTP/1.0 301 Moved Permanently");
      header("Location: $location"); 
  }

@@Jack_mcs Dude that's awesome. It is redirecting any URLs that I write in with the parameter ?products_id=# however, first thing, it is adding a second /. So the url looks like sitename.com//prouducts-name What happened to produce that? Secondly, Can I use the same code to remove:

?page=1

?cpath=40

?manufacturers_id=10

?page=1&sort=3a

 

These are a few of the things I have seen google find for some reason.. some kind of way.. that I want to get removed. Thanks!

Link to comment
Share on other sites

For the double slash, try changing this line

$location = substr($_SERVER['REQUEST_URI'], 0 , -($lgth));

to

$location = substr($_SERVER['REQUEST_URI'], 1 , -($lgth));

For removing the other things, the code will do that if you change the part in the first line (where the html?p... is). But you need to be sure those are extra parts of the url, not part of a valid url. For example, someone might have a link to the shop that is http://sitename.com/index.php?cPath=40 and if you use the code on it for just cPath=40, that link, which is valid, would no longer work.

Support Links:

For Hire: Contact me for anything you need help with for your shop: upgrading, hosting, repairs, code written, etc.

All of My Addons

Get the latest versions of my addons

Recommended SEO Addons

Link to comment
Share on other sites

For the double slash, try changing this line

$location = substr($_SERVER['REQUEST_URI'], 0 , -($lgth));

to

$location = substr($_SERVER['REQUEST_URI'], 1 , -($lgth));

For removing the other things, the code will do that if you change the part in the first line (where the html?p... is). But you need to be sure those are extra parts of the url, not part of a valid url. For example, someone might have a link to the shop that is http://sitename.com/index.php?cPath=40 and if you use the code on it for just cPath=40, that link, which is valid, would no longer work.

@@Jack_mcs yep, that worked perfectly.

 

So I should do something like:

 $pos = strpos($_SERVER['REQUEST_URI'], "html?cpath=");

and

 $pos = strpos($_SERVER['REQUEST_URI'], "html?manufacturers_id=");

To strip those extra strings? Just add each line to the query?

Link to comment
Share on other sites

@@NuDreamer I should have mentioned that once the url's are cleaned, you should remove that code since it will needlessly add more work for the code and could slow the site down.

Support Links:

For Hire: Contact me for anything you need help with for your shop: upgrading, hosting, repairs, code written, etc.

All of My Addons

Get the latest versions of my addons

Recommended SEO Addons

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...