Anyone can tell me how can I rewrite my url from www.example.com/user.php?id=1 and id=1 will get the name from mysql.

Like example id=1 user name is "abcdef". Now the parameter(id=1) will get result from database and display "abcdef" to url(www.example.com/abcdef).

I think you have it backwards... Dont you want your visitors or links to have the more friendly version.. say:
www.example.com/abcdef and then you want that to be mapped to a page user.php and display user information?

If so, that's a rewrite. However if your users are accessing www.example.com/user.php?id=1 and you want to show them www.example.com/abcdef in the URL, that's going to be a redirect.

I would think you are interested in the first example. If so, you need a simple rewrite rule something like this (im doing this from memory so test it)

RewriteRule ^(.+)$ user.php?id=$1 [NC,L]

A rewrite rule like this should take any number of characters after the www.example.com/ and send them to user.php and passing the value as a parameter.

Then on user.php, you read the value and perform a database lookup (based on ID or username, or whatever parameter you are passing) and display the information to the user.

I would think a better approach would be to be more specific in the friendly URL so that you can do other rewriting and redirecting. For example, I would suggest...

RewriteRule ^user/(.+)$ user.php?id=$1 [NC,L]

The difference here is that your friendly URL would look something like this:

www.example.com/user/devianleong which maps to user.php?id=devianleong

Anyway, this should help you to move forward...

TQ your suggestion =D

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.