mod_rewrite – Part 1: create your “fantasy” URL


“Hey, guys! I just hear a fantastic ethnic music at blablabla.com/?cat=312&id=e0347&p=93447”, talk Aya to her friends.

mmm… its hard to say (and remmember) that URL. I am sure, you will agree with me. How about if Aya say like this, “Hey, guys! I just hear a fantastic ethnic music at blablabla.com/bestethic.html”.

Yes, you can made ‘fantasy’ URL to instead of dynamic URL.

I know, you are realy ‘tee-ou-pee’ (read: TOP) build database web application. You can build complex eCommerce. With your skill, its not difficult to understand this URL:

1 http://www.yoursite.com/cat=02837&subcat=0246&product_id=001

May, you will say:

1 cat (category) = ethnic (represented: 02837)
2 subcategory (subcat) = java (represented: 0246)
3 and
4 product id (product_id) = gamelan java (represented: 001)

as programming code, its not difficult. But how with your fanatic customer. Its realy difficult if he want to say to his friends about your product in web.

It will be more easy if he can say, blablabla.com/bestethnic.html

How modify dinamic URL to static URL like this? Must we create a page/product? NO!

You can use mod_rewrite in apache to build ‘fantasy URL’ (I said ‘fantasy URL’ because its not realy page). You can use that module to create any URL to represent a dynamic page. Look example below:

1 ethnicmusic.html  = product.php?cat=203&prodid=934746
2 good-coding.html  = article.php?article_id=2336

Okey, are you ready? lets read another article in this series.

As phpeveryday.com

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s