Personalized URLs
How someone implement personalized URLs in a website?
For example http://www.facebook.com/john
开发者_开发百科or For example http://www.facebook.com/john.smith
Having in mind that the users choose their names (which will be unique and can not change once chosen).
Platform is Apache, PHP, Mysql
Thank you
Using mod_rewrite to redirect traffic to a different path which handles the routing.
If you look at many of the popular PHP frameworks they suggest using a provided .htaccess file which forwards all requests to index.php and from their include their own routing class/script
As part of the routing, you could check if the path matches an existing user, and then make the request display that users page.
You'd use mod_rewrite
to rewrite all incoming requests to something like http://example.com/index.php?q={request}
. Then you can grab $_GET['q']
in PHP and do whatever you want with it. If it looks like a username, display the user's profile page, if it looks like the name of another page, include that page.
精彩评论