User View Profile
I am building an application for my client and I am not using any frameworks . Question came up when building viewing user profile
My client wants to see the user profile URL like
mywebsite.com/Johnd - should give Johnd profile mywebsite.com/KJohns - should give KJohns profile
I have implemented URL mapping like http://mywebsite.com/viewprofile.php?id=Johnd . But I am not sure how to map viewprofile.php?i开发者_JS百科d=Johnd to just 'Johnd' .
Could some body please advise ?
mod_rewrite might be what you're looking for (if you're running apache at least). Have a look at http://www.workingwith.me.uk/articles/scripting/mod_rewrite for a brief intro/tutorial to see if that's the type of thing you need.
If you are using Apache, adding a rule to your .htaccess
file that says:
RewriteRule .*/profiles/(.*) viewprofile.php?id=$1 [NC, L]
Will let people access http://mywebsite.com/viewprofile.php?id=Johnd
through http://mywebsite.com/profiles/Johnd
Alternately, if you wanted to use PHP to do this, you could map all your requests to a single file and if the request is not your list of urls, assume it's a user and route it there. (Take a look at the code for Tweetable MVC for the basics.)
use modrewrite and ataccess file
there is a lot of tutorials on the net called pretty url, check this one for ex.:
http://wettone.com/code/clean-urls
精彩评论