gmhk
gmhk

Reputation: 15940

URL Generation Technique with PHP

I have a build a web portal based on the Cricket concept, I have build a Custom based CMS where I can upload the News for the site

Once I upload the news, the URL Will be like this http://cricandcric.com/news/news.php?id=841&An-emotional-moment:-Dhoni.html

But I am trying to have the above Url as follows (some thing like this) http://cricandcric.com/news/An-emotional-moment:-Dhoni.html

Or similar to Stackoverflow.com,

Can any one please help me how can i build that? Do I need to rewrite the URL ?

Upvotes: 3

Views: 420

Answers (3)

OM The Eternity
OM The Eternity

Reputation: 16204

yeah Dude, .htaccess file will resolve all your Riddles.....Chk This--- How to use .htaccess file for rewriting URL?

Upvotes: 0

Tom Bartel
Tom Bartel

Reputation: 2258

Yes, as far as I can see you need to rewrite the URL. The URL "http://cricandcric.com/news/An-emotional-moment:-Dhoni.html" might be rewritten to "http://circandcric.com/news/index.php?title=An-emotional-moment:-Dhoni". Then, index.php has to figure out the correct news item from this title. This might be a source of problems (transformation of the title into URL-compatible string and back again), and, as Chad pointed out, the title has to be unique. If you get into trouble, check out how Stackoverflow handles this (ID as part of the URL, then title).

Upvotes: 0

Chad Birch
Chad Birch

Reputation: 74558

Yes, this is typically done with URL rewriting. This is a great intro to it.

Note that you'll have to make sure that the titles are unique, if you're removing the ID from the URL. (And you might as well get rid of the ".html" too)

Upvotes: 1

Related Questions