I\'ve been through a few similar posts, Facebook Like Custom Profile URL PHP
Custom URL / Apache URL Rewriting
But its still not clear, the actual method/pr
It's going to be impossible to put any details as an answer because you've got to build this system of yours and there's more than one way to do it. Design decisions will need to be made based on the way you want things to work and what you already have (they're going to have to work together in some way).
Say you've already got a system for creating users (and it sounds like you do) and you already have a system for viewing profiles. You'll need to extend this system so that you store an extra "my_vanity_url" field in your user table in your database. This field needs to be unique. When a user edits their profile, they have the option of changing this to whatever they want (limiting it to only letters and numbers and dashes for simplicity).
Next, when you display this profile, say it is via /profile.php
, your code needs to check a few things.
$_SERVER['REQUEST_URI']
you can see either /user/some-vanity-name
or /profile.php?u=1234
.1234
is./user/my_vanity_url_value
(replacing my_vanity_url_value
with the value of that column).So now, if you go to http://your.domain.com/profile.php?u=1234, your browser gets redirected and the URL address bar will say http://your.domian.com/user/my_name.
Next, you need to be able to take that unique name and turn it back into the old ugly looking profile page. Two things need to happen here:
profile.php
once more to take an optional vanity name as opposed to a user_id/profile.php
For the first thing, you simply look for a different $_GET[]
parameter instead of whatever it is for a user_id. Say it's called name
: so look at $_GET['name']
, see if it exists, if it does lookup the user in the user table whose vanity url name is $_GET['name']
. Return the profile of that user.
For the second thing, you just need to put this in the appropriate place in your htaccess file in your document root:
RewriteEngine On
RewriteRule ^/?user/([A-Za-z0-9-]+)/?$ /profile.php?name=$1 [L]
This is just an example for how to implement something like this. It may be completely inapplicable for what you have, but it should give you an idea of what you need to do.