Background
As one would notice in stackoverflow's url structure, every question has an id followed by the question title. For example:
http://stackoverflow.com/questions/1039725/how-to-do-url-re-writing-in-php
The url above has the question id: 1039725 The question title is: how-to-do-url-re-writing-in-php
Just to play around with this url, even if one were to enter some junk stuff for the title part, the same question content will be displayed as long as the question id is there. For example the following url will also give the same content.
http://stackoverflow.com/questions/1039725/some-junk-stuff-title
and MORE IMORTANTLY the url bar automatically changes to:
http://stackoverflow.com/questions/1039725/how-to-do-url-re-writing-in-php
My Question
I understand that stackoverflow perhaps uses .htaccess to redirect all urls with the question id to some backend (let's say php page) to process it. But how does the address bar change to the actual question title automatically?
Most important thing is: how to achieve displaying the complete url without redirecting to any real folder? i.e. I don't want to use header() redirection in php to some folder.
The idea is to avoid creating unnecessary web folders for each question just for the sake of redirection.