I'm wonder how WordPress
or some other websites rewrite URLs without any identifier mentioned.
for example in WP
when i open Permalink Settings
can select a custom URL format as below.
http://localhost/wordpress/sample-post/
Just post title has been mentioned and there is no way to know the Post ID
apparently. Now thinking of how WP know which post have to be loaded ?
What i think myself is that this formatted URL has not been rewritten and just is a sample that WordPress use to rewrite every post after i create it. So every time i write a post it adds a new rewrite to .htaccess
file.
But this solution is not logical and make us to have a dirty htaccess
file and is very hard to maintenance because a lot of conflicts are likely.
Another solution is to think that there is no regular rewriting at all, and WP
is processing URL itself, so when current URL matches to sample URL it know that's time to load an specific post.
This is feasible too, but the main problem still remained that how it know which Post have to be loaded ? Is it searching on DB using title ?! So how it can guarantee that titles are unique ?
That's a big challenge in my life ;)