how does myspace create your URL?

Discussion in 'PHP' started by jnm, Nov 15, 2006.

  1. #1
    i know myspace uses .cfm, but if it has anything to do with php, i'd like to know that.

    anyway, how does myspace use a small url for all accounts instead of the long profile url? mod rewrites?

    if so, how does it get around folders in the root directory?

    and how does it know to use your username? is it just a simple script that truncates the url to everything after the slash and determines if it is a short url and if so, looks it up in the database?

    dumb at this :(

    thanks.
     
    jnm, Nov 15, 2006 IP
  2. crazybjörn

    crazybjörn Peon

    Messages:
    270
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #2
    .cfm is actually commonly associated with cold fusion. Specifically Cold Fusion Template in cfm's case. As for short urls, I don't think that it's mod_rewrite in myspace's case since they use Microsoft-IIS 6.0 server with ASP.net. Though yes, the same effect can be easily achieved with apache's mod_rewrite module.
     
    crazybjörn, Nov 16, 2006 IP
  3. ajscottsr

    ajscottsr Peon

    Messages:
    388
    Likes Received:
    28
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Let me give you an example from one of my sites that may shed some light on this topic. Keep in mind, this site is PHP, its on an Apache server and it DOES make use of mod_rewrite.

    OutBlogger.com - http://www.outblogger.com

    When a user signs up, they get a URL that looks like this:

    username.outblogger.com

    For example, "humor" is a user on the blog. That URL is:

    http://humor.outblogger.com

    Now, the URL is actually something like http://www.outblogger.com/blog.php?user=humor

    In order to make this happen, a number of things had to be done.

    1. In order for humor.outblogger.com, user.outblogger.com, etc.outblogger.com to work, we have to make sure there are valid DNS entries for each of those (otherwise you'll get a DNS error message). Rather than actually adding hundreds of entries to the DNS records, we add a single entry with a wildcard which is *.outblogger.com. This means that no matter what you type in, e.g. asfjjldfsdls.outblogger.com, the DNS server will accept that domain and direct you to the webserver that houses OutBlogger.com

    2. Then we use mod_rewrite to detect the host and change it to proper URL. The mod_rewrite entry that takes care of this is as follows:

    RewriteCond %{HTTP_HOST} ([^.]+)\.outblogger.com [NC]
    RewriteRule ^$ /blog.php?user=%1 [L]

    This is what converts humor.outblogger.com to www.outblogger.com/blog.php?user=humor

    Of course if you are using urls like:

    http://www.youdomain.com/username, you don't need to worry about the DNS but you could still use mod_rewrite to make that dynamic.
     
    ajscottsr, Nov 16, 2006 IP