profile.php的网址

I'm creating a small social network website. Like every social network site I have a profile page calles profile.php. I can access a profile like this: profile.php?id=6 but I also have a .htaccess file, where I can now just type in: mysite/username. And it's working really good. So my problem is now. When a user types in profile.php?id=7 it should automatically convert the url with the specific username. And if I type in only profile.php it should redirect automatically to my profile.

Thanks for your help guys.

If you want it to automatically change the URL, I'd create a controller of sorts and issue a redirect once it's all retrieved.

I'd suggest making profile.php a very simple page, something that only looks up the user by his/her id and then creates the URL to redirect to.

A pseudo-code implementation would look like:

<?php
$id = $_GET['id'];
//... look up username from database ...
header("Location: /mysite/" . $username);

I'm not sure how your .htaccess is setup, but you'll need to be careful that you don't end up in a loop with the redirect.