views:

29

answers:

3

I am looking to create vanity url for my users. How can i do it?

I want something like username.domain.com

My second question is, can i also customize this upon client requests? Like let's say, Client says add a feature to my account, will I be able to do it since it's almost like a separate site within my site?

A: 

You can look at this:

http://stackoverflow.com/questions/3655139/how-to-create-sub-domain-for-user-opon-sign-up

Sabeen Malik
I don't understand it. If you create a sub.link is that almost like having a separate website that you can add features to??
AAA
thing is you have all the tools, you need to figure out how to use them best for your own situation. If there will be physical differences in the files being served on each subdomain, then you will need to copy your basic set of files into the new user directory when a user signs up. If these changes are like "settings" you can save these variations to the database and make the adjustments to pages based on user settings and you wont have to create a separate directory for each user.
Sabeen Malik
+2  A: 

You could use URL rewriting e.g. via Apache's mod_rewrite to solve this.

For security and practical reasons however, I do not recommend using something like username.domain.com unless you carefully filter out user names like www. Better use username.u.domain.com or something similar.

Here an example for rewrite rules using HTTP redirection.

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.domain\.com$
RewriteCond %{HTTP_HOST} ^([^.]+)\.u\.domain\.com$
RewriteRule .* http://domain.com/user/%1 [R,L]

Alternatively, you could also use a DNS wildcard / catch-all entry and extract the user name part before your domain using a regular expression, e.g.

function getUserNameFromHost() {
    if ( !preg_match('`^(\w+)\.u\.domain\.com$`', $_SERVER['HTTP_HOST'], $matches) )
        return false;
    else
        return $matches[1];
}
Archimedix
A: 

URL rewrite. Use mod_rewrite to display a subdomain in the address bar, but retrieve a different URL internally.

eg: aaa.domain.com should go to domain.com/users/aaa

Stewie
although My answer is right, User: Archimedix above with this answer: http://stackoverflow.com/questions/3807833/how-to-create-sub-links-for-user-on-sign-up/3807899#3807899 deserves the "check", not this one, Can you change it please ?
Stewie
Just did it for acrhimedix
AAA