Supporting twitter-like user page urls with apache/php?
I'm using php on apache with mysql.
I want to let users enter a url into their browser to see a custom user page for themselves, just like twitter does. For example, they could enter urls like:
www.mysite.com/johndoe
www.mysite.com/janedoe
and see开发者_高级运维 that user's page. How could I do this with php and apache? I don't want to create a folder on disk for every user like above, I'd instead kind of like to catch the url and generate the page on the fly for them,
Thanks
What you are looking for is URL rewriting and it can be done using Apache mod_rewrite.
For example, if your urls are
www.mysite.com/user/johndoe
www.mysite.com/user/janedoe
and you setup a mod_rewrite rule
RewriteRule /user/([a-zA-Z]+) /get_users.php?username=$1
then in get_users.php you can retrieve the value for username from
$_GET["username"]
精彩评论