Forum Moderators: phranque

Message Too Old, No Replies

how can i do this?

http://www.example.com/user.php?id=uid to http://www.example.com/username

         

PHP2MySql

10:45 am on Nov 8, 2007 (gmt 0)

10+ Year Member



Hi,

i have question,
how can i change the url (http://www.example.com/user.php?id=uid)
to
http://www.example.com/username

uid = the id of user in db
username = the username of the user

Thaaaaaaaaankx

jdMorgan

3:26 pm on Nov 8, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you have server config access and can modify httpd.conf or conf.d, you can define a RewriteMap to invoke a small PERL script to look up the UID in your database, given the username.

The script is then executed during the URL-to-filename translation phase of the Apache API, and returns the translated value to mod_rewrite in httpd.conf, conf.d, or even in .htaccess. However, server config access is required in order to define the RewriteMap.

Alternatively, you could rewrite all /username requests to a modfied version of your /user.php script, have the script look up the uid, and then return (that is, 'include') appropriate page content for each user.

Be aware that the links you publish on your pages must be in /username form, and you then need to translate those URLs, when requested from your server, to the /user.php?id=uid form to properly invoke your page-delivery script.

A problem you'll need to consider is that you must 'tag' the /username URLs in some way so that they can be differentiated from normal subdirectory requests -- The server must be given some way to tell, for example, a request for the 'well-known' privacy policy file named /w3c/p3p.xml from a request for username 'w3c'.

This can be done by using a URL prefix, such as /users/username, by using a subdomain such as [users.example.com,...] or any other method that makes the distinction explicit.

Jim