-1

i have a oscommerce site, i wan to use seo freindly urls, I got a tutorial from here

I basically wanted to change the ID number present in a URL to a URl that will contain name of product or category in it. an example of such url is

http://katanamotorsports.com/innovative-mounts-steel-mounts-prelude-replacement-mount-p-1075.html

i want to modify .htaccess file so that these seo friendly url are actually redirected to respective page with respect to category and product.

i am new bee in learning, and i am totally a new bee in .htaccess

can anybody help me?

anubhava
  • 761,203
  • 64
  • 569
  • 643
Zaffar Saffee
  • 6,167
  • 5
  • 39
  • 77

2 Answers2

1

You have to use a RewriteRule in your .htaccess to map the external URL (as visible by a user) to your internal version.

What you want to do is activate the RewriteEngine, then write a RewriteRule that will drop the first part of the URI.

RewriteEngine on
RewriteRule ^[a-z0-9\-]+-p-([0-9]+)\.html$ /product.php?id=$1
RewriteRule ^[a-z0-9\-]+-c-([0-9]+)\.html$ /category.php?id=$1
Tchoupi
  • 14,560
  • 5
  • 37
  • 71
  • thanks for this, one clarity, will redirect each page to it resptive php page? – Zaffar Saffee Mar 02 '12 at 21:59
  • 1
    Yes this will rewrite any url starting with (letters/numbers/dash as separator) and ending with a numerical id to some php page. The $1 allows you to write the found ID at the right spot. – Tchoupi Mar 02 '12 at 22:02
  • can you explain the mapping here? what i want to know is, how this redirect will take effect? wether a database will be searched for it? how exact produect id will be determined? by matching the name in some where in the files or database? – Zaffar Saffee Mar 02 '12 at 22:06
  • 1
    If someones goes to this url http://katanamotorsports.com/innovative-mounts-steel-mounts-prelude-replacement-mount-p-1075.html he won't see any redirection. But on your server the request will be sent to product.php?id=xxx and you'll be able to normally see it in your script. Then you can query your database from your PHP (or other language) script. – Tchoupi Mar 02 '12 at 22:08
  • if you see the structure of external URL, you will see '-p-' in it, denoting product, and in some url it will be '-c-' , denoting category, what i think of seeing the answer that, it will redirect all the pages to product.php, Am I correct? please update the answer to address this issue – Zaffar Saffee Mar 02 '12 at 22:14
  • what if my orginal URL is http://katanamotorsports.com/product_info.php?products_id=1075 ? – Zaffar Saffee Mar 03 '12 at 19:36
  • should it be /product_info.php?products_id=$1? – Zaffar Saffee Mar 03 '12 at 19:37
0

Please don't use "SEO Friendly" urls like this. They are NOT currently SEO friendly. Search engines liked them 10 years ago. In the last five years they really only hurt.

  • Google gives almost no weight to keywords in the url
  • Google gives weight to sites that it determines satisfy users

So, don't design urls for search engines, design them for users. Users like

  • Urls that are short (maybe they can type them or remember them)
  • Urls that are meaningful (They can see what they are about before clicking on them)
  • Urls that don't contain repetition or numbers like ids

It would be far better for you to have your url be:

http://katanamotorsports.com/prelude-replacement-mount
Stephen Ostermiller
  • 23,933
  • 14
  • 88
  • 109