i am creating php social project which every user has his own profile ( vanity url ) like :
www.mysite.com/myname
and i used this codes :
1.profile.php
<?php
ob_start();
require("connect.php");
if(isset($_GET['u'])){
$username = mysql_real_escape_string($_GET['u']);
if(ctype_alnum($username)){
$data = mysql_query("SELECT * FROM members WHERE username = '$username'");
if(mysql_num_rows($data) === 1){
$row = mysql_fetch_assoc($data);
$info = $row['info'];
echo $username."<br>";
}else{
echo "$username is not Found !";
}
}else{
echo "An Error Has Occured !";
}
}else{
header("Location: index.php");
}?>
.htaccess:
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^.]+)$ $1.php [NC]
RewriteCond %{REQUEST_FILENAME} >""
RewriteRule ^([^.]+)$ profile.php?u=$1 [L]
and this code works and if i typed www.mysite.com/username it show the profile of the user.
now iam asking to create a sub folder to the vanity url .. i mean if i typed www.mysite.com/username/info
it echos info of the username which is stored in the database .. any ideas ?
I highly recommend Rewriting everything to one script called a Front Controller:
Then you can handle the url in
front_controller.php
and figure out which page to load. Something like: