tags:

views:

24

answers:

1

Hi,

My current URL look like this.

http://example.com/news.php?id=25&cat=news&date=01092010&title=this-is-the-first-title

i want to make it cleaner like

http://example.com/news/01092010/this-is-the-first-title

i just know the basic of how .htaccess works with the basic understanding of its directive, how do i achieve this?

Edit : i dont want the id to be displayed.

thank you

+1  A: 
RewriteRule ^([a-z]+)/([0-9]+)/([a-z-]+)$ /news.php?cat=$1&date=$2&title=$3

But note the id is not contained in this "pretty URL"! Therefore, you must manually look this up (or you directly fetch the news item) in news.php based on the values from $_GET['date'] and $_GET['title'].

The rule above will convert a request on the form http://example.com/news/01092010/this-is-the-first-title into http://example.com/news.php?cat=news&date=01092010&title=this-is-the-first-title.

jensgram
i dont want the id to be displayed. how do i do it?
Ibrahim Azhar Armar
What you *could* do is add it to the "pretty URL", e.g. `http://example.com/news/01092010/25-this-is-the-first-title` and then match it (`^([a-z]+)/([0-9]+)/([0-9]+)-([a-z-]+)$`). Alternatively you must do a look-up.
jensgram
@Ibrahim, then you will need to lookup title/date from the database and get the matching record, which should be the requested article.
aularon
@Ibrahim Azhar Armar Ah, then you *must* do a look-up, cf. @aularon's comment.
jensgram