I'm creating a site that involves profiles, and I was wondering how would I go about getting users to have "safe urls" for there profiles?
eg;
Username: dalehay
Profile URL: http://www.website.com/dalehay
(Sends visitor to)
Real URL: http://www.website.com/profile.php?name=dalehay
Any ideas?
Redirect
Moderator: General Moderators
- evilmonkey
- Forum Regular
- Posts: 823
- Joined: Sun Oct 06, 2002 1:24 pm
- Location: Toronto, Canada
You can use a trick such as a custom error page that will read the URL and redirect it properly. If there page really doesn't exist, then show an error message. Something like this:
Not sure if there's a better way of doing this, but this is a trick that sorta came to me.
Code: Select all
<?php
//error404.php
$url = $_SERVER['REQUEST_URI']; //should return "http://www.website.com/dalehay"
$profile_name = strstr("/", $url); //should return "/delehay"
//run a mysql check or something to see if a profile with such name exists
if (/*check succeeds*/){
header ("Location: http://www.website.com/profile.php?profile=dalehay");
}
else{
include ("404.php"); //this is your "not found" page
}
?>Found the solution.
(I'll post it for anyone with this problem)
.htaccess
(Make sure this is in the root directory)
(I'll post it for anyone with this problem)
.htaccess
Code: Select all
RewriteEngine on
RewriteRule ^([a-zA-Z0-9_-]+)(/)?$ profile.php?name=$1- evilmonkey
- Forum Regular
- Posts: 823
- Joined: Sun Oct 06, 2002 1:24 pm
- Location: Toronto, Canada