moonwalker
moonwalker

Reputation: 485

How to use mod rewrite with php?

I'm just wondering. In some websites I see the following: http://www.website.com/the-title-of-my-new-book-2011.html

I know how to use a mod rewrite, but I wonder how they get the title separated by the "-" sign. And I don't see any ID, meaning they are using the title of the book to get the ID and show the information from the database. How do they get rid of the "-" sign? And more importantly: How do they link to each article on their website? Which functions are used to achieve all this?

Thanks in advance.

Upvotes: 0

Views: 147

Answers (2)

deceze
deceze

Reputation: 522091

These things are called slugs. When entering a new product, a slug is probably created semi-automaticlly based on the name of the product, for example by removing all non-latin characters, making it lower case and replacing spaces with dashes. This is saved together with the product. When visiting the above URL, the .html is stripped and the rest is taken as the slug and used for looking up the product in the database.

Upvotes: 2

Pekka
Pekka

Reputation: 449435

They probably catch the full path ( /the-title-of-my-new-book-2011.html) using mod_rewrite, cut off .html and 2011, and do a lookup of the rest against a column in their books database.

Upvotes: 1

Related Questions