Forum Moderators: open

Message Too Old, No Replies

Link

         

Wolf6112

5:41 pm on Nov 30, 2009 (gmt 0)

10+ Year Member



I wasn't sure where to post this. But we have an E-commerce site, and all products are simply loaded as product.asp?product=123 - we want to change this as this would improve our SEO. How do you create URLs as follows:

http://www.example.com/products/Laser-Printers/259040/HP-LaserJet-P2055DN-35ppm-1200dpi-Network-Laser-Printer

Essentially, use the category, the sku, and then title as the URL?

rocknbil

6:23 pm on Nov 30, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome aboard Wolf6112, there are many ways . . . the most used, I think, is using mod_rewrite in .htaccess directives. I will cite PHP examples, that's everyone's "darling" scripting language . . . I see you have .asp, the logic is the same and you can do similar stuff using MS servers.

But before you get started, you don't change the url from query string to keyword-url, it's the other way around. You create "friendly URL's" on the site and in your product feeds, and redirect/rewrite them accordingly. So if you have a directive like so,

RewriteRule ^some-non-existent-url(.*) /path/to/script.php

This would make any request to your domain that begins with "some-non-existent-url" to rewrite to script.php - while the address bar remains as "some-non-existent-url". Then script.php is what parses out and manages the URL.

Example:

example.com/some-non-existent-url/laser-printers/deskjet

script.php receives this as $_SERVER['REQUEST_URI']. You then split the URI on slashes,

$params = explode('/',$_SERVER['REQUEST_URI']);

Then pop the ones off you need.

$product = array_pop($params);
$category = array_pop($params);

So now you have 'laser-printers' and 'deskjet'. To insure your "old" query strings still work, you can do something like this:

$product=(isset($product))?$product:$_GET['product'];
$category=(isset($category))?$category:$_GET['category'];

Then you'd do

$product=preg_replace('/\-/',' ',$product);
$category=preg_replace('/\-/',' ',$category);

select * from table where product_title='$product' and category='$category';

You will have to work out some logic converting these to numeric values if that's what you're using now, but that's the gist. Another approach is to store "URL" as a field in the database, and look for that value instead.

Now your program can continue as it normally does, without major changes, because you've checked for the URI first, if it's present, use it, otherwise, look for the usual values in $_GET.

This way old query strings will still work, but you can begin porting to friendly URL's fairly quickly.

[edited by: rocknbil at 6:27 pm (utc) on Nov. 30, 2009]

Wolf6112

6:26 pm on Nov 30, 2009 (gmt 0)

10+ Year Member



Thank you for quick response, unfortunately, we are using ASP, not PHP - site been around for 6+ years, cannot change scripting language.

rocknbil

6:27 pm on Nov 30, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



See edited post - same concepts. :-)