0

Possible Duplicate:
How to: URL re-writing in PHP?

My intention is to change the variable (id) passed on the URL with another variable (custom text). To more clear I would like to change:

from

www.mysite.com/page.php?id=14

to

www.mysite.com/page.php?id=the_best_product_for_them

or even better

www.mysite.com/product/the_best_product_for_them

There is already a table on my database that associates the id='14' with the text 'the_best_product_for_them' (id, product_name)

I guess this is what wordpress does with permalinks. I know also how to do it manually with a .htaccess file, but I would like to do it dynamically. What I need is a direction where to start from and what is needed to achieve this.

The server is Apache, the code is in PHP.

Many thanks, Giulio

Community
  • 1
  • 1
Giulio
  • 1

1 Answers1

1

I guess you'll find solution in here: Url Mod-Rewrite Get new Page with ID

# catch URL and  rewrite to index.php
RewriteRule ^product/([A-Za-z0-9-]+)/?$ index.php?id=$1 [NC,L]
  • be sure that you have mod_rewrite at your Apache Server
Community
  • 1
  • 1
arekstasiewicz
  • 383
  • 2
  • 11
  • 24
  • I think you missed the point. OP knows how to do it "manually with a .htaccess". He would like to do it dynamically. – Tom Jan 30 '13 at 22:23
  • Hi Tom, that's correct. So far the answers given were not really helpful. Except the comment from "trollster", the input was a good start: VANITY URLs --- thank you all! – Giulio Feb 02 '13 at 13:12