Url rewriting using values from the database

hi,
if anyone can help me out i will be really thank full to that person.

i have created a website using php/mysql technology.

it has got a url pattern like
http://www.example.com/article-view.php?articleid=13

but i want to rename it to a seo friendly name

like:
http://www.example.com/acupressure/high-touch-acupressure/

the article title is kept in the database. i want to fetch the title from the database (mysql) and use that as the url for the website.
moreover the title that is stored in the database is High Touch Acupressure.
i need to make it high-touch-acupressure (all in small & filled up with dashes “-”)

.htaccess can be used for this but i am not able to make the url dynamic.

many thanks

Then you are going to end up doing something like:

a) output urls like this:

http:// www. example.com/acupressure/high-touch-acupressure/

b) have a mod_rewrite rule like this:


RewriteRule ^/accupressure/([-a-zA-Z]+)/?$ /accupressure.php?slug=$1 [L]

*untested and could be improved to make sure that there is a min/max amount of chars

c) then create the accupressure.php file which looks up that slug and works out that it needs to look for id number 13 in your database.

(dropping step c) is what I was advocating)

But there is no getting round the fact you are going to have to read some specs, this intro is one of the best, but you’ll end up in the official Apache docs at some time.

hi,
i don’t want the article number to show up in the url. also what do i have to write in .htaccess file to make the changed dynamic ?

Instead of having a numeric key, 13, in your database you could use a distinct “slug”

Articles

id : high-touch-acupressure
title : High Touch Acupressure

Then, you would not need to de-reference the number 13, you could use a regex to check whether the slug contains just letters/numbers and dashes.

If you search this forum for the word slug you should get some ideas and code to get you going.

If this has not answered your question then be a bit more specific.

The other term you might be looking for is mod_rewrite.

How about doing:

$url = strtolower(str_replace(' ', '-', $title)) . '-' . $id;

to produce: [noparse]http://www.example.com/acupressure/high-touch-acupressure-13[/noparse]

Then use mod_rewrite to map it to the actual url.