PHP and URL help.

I am creating a site; and on this site you have profiles. You can go to the profile by doing this:
www.site.com/profile.php?id=1

How do you make it so you can do this:
www.site.com/username

You can do this with url rewrite rules, using .htaccess
For example:

.htaccess[code]
RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ /profile.php?user=$1 [L]
[/code]

In your example, this uri www.site.com/username will be interpreted as www.site.com/profile.php?user=username, and then within the script you can find user id by username.

Sponsor our Newsletter | Privacy Policy | Terms of Service