2

Possible Duplicate:
.htacces to create friendly URLs. Help needed

I need help on understanding how to display a pretty URL for a URL with dynamic parameters.

In my website, when you click on the product link it will take you to the page with this url: http://example.com/products?id=1002

How can it be changed to display http://example.com/products/1002?

Community
  • 1
  • 1
  • 2
    By changing the output. Also use the search on this website, we had that question a few times already. You might see yours downvoted because of that. – hakre Aug 16 '12 at 19:07
  • Did you read [Apache mod_rewrite Introduction](http://httpd.apache.org/docs/2.2/en/rewrite/intro.html) It is the minimum reading before attempting to use URL rewriting. – Jocelyn Aug 16 '12 at 19:07

1 Answers1

1

Step 1: change your pages so that the product links that you generate look like this: http://example.com/products/1002. You control this content, you can generate your links to look like anything you want. If you're using some kind of framework, it may even have a built in mechanism for doing this.

Step 2: add this in the htaccess file in your document root:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^products/(.+?)/?$ /products/?id=$1 [L]
Jon Lin
  • 142,182
  • 29
  • 220
  • 220