花哨网址的工作

in some websites that i saw, urls are fancy and it contains text only. No ids(numbers) or anything.

Example: In stackoverflow, a sample url to a question is: http://stackoverflow.com/questions/3740229/how-can-i-rewrite-url-to-fancy-url Here, 3740229 is question id. So using mod rewrite rules we can get question id and pass it to our php page to fetch details of that question. But in some sites, that will be absent. Example: http://anothersite.com/questions/how-can-i-rewrite-url-to-fancy-url

So how do we fetch details ? that is how to identify question using this how-can-i-rewrite-url-to-fancy-url instead of question id ?

That's often called a URL slug, and it does serve as a unique id for the content it retrieves. The database stores that unique value how-can-i-rewrite-url-to-fancy-url and retrieves its content instead of a retrieving based on a numeric id.

Note that behind the scenes, the database very likely still does have a unique numeric id for each record, but that value isn't exposed to end users, which offers a tiny bit of security through obscurity and prevents crawling scripts from simply incrementing the value to scrape all of a site's content.

When storing new content, process the title accordingly (replace spaces with hyphens, convert to lowercase), and ensure that the value created is unique in your database. If it isn't, you need to append a number or random string onto it to ensure uniqueness. Then use that value instead of the numeric id in your URLs.