Results 1 to 7 of 7

Thread: creating virtual user folders

  1. #1
    Join Date
    Dec 2005
    Location
    Tempe, AZ
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default creating virtual user folders

    I'd like users to have their own easy to access URL when signing up for my service (i.e. domain.com/username). My first thought would be a .htaccess file...but just how big can a htaccess file be? We're talking thousands of users. I'd estimate the htaccess being about 300KB doing this. I could do it easily like that, but there has got to be a better way? I'm familiar with htaccess, but not at its speed.

    Sample situation
    User signs up under name "rider45"
    User is assigned the URL domain.com/rider45
    URL domain.com/rider45 needs to really point to something like domain.com/profiles/profile.php?user=rider45

    A rewrite rule that said domain.com/$var redirect to /profiles/profile.php?user=$var would work flawlessly. I searched for hours and couldn't figure this out. I see examples of things like it but don't understand exactly how it is working.
    Last edited by 4bidden; 09-14-2006 at 08:23 AM.

  2. #2
    Join Date
    Dec 2005
    Location
    Tempe, AZ
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Nobody?

  3. #3
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    How about
    domain.com?user

    With php, you could easily check for the ? (and something after it), and if it's there, then redirect to the second half of the URI.

    Also, you could format it a couple ways--
    domain.com?user
    domain.com/?user
    domain.com/page.php?user
    ??domain.com/page.php/user (*might work*)

    However, you could need the question mark (except in the last example, which i'm not sure is valid. You could also use a #, though the ? is the usual symbol to preceed the variables with php, whereas the # is used to preceed a target/anchor on the page.

    The other way I can think of doing this would be to actually create a custom error page, and have that page use php then redirect based on the request URI. That's a nice litttle trick. However, this is obviously a trick, and would cause problems for browsers that don't accept your custom 404 page, such as, y'know, Internet Explorer. Should would great in Mozilla, though.
    I wouldn't really recommend this.
    However, maybe there's some way you can specify on your server how errors are handled and use that to your advantage... create a new behaviour based on this situation, or something. Though that would probably be quite complex.

    Aside from those ideas, .htaccess sounds good, or some other server programming. Can't do it with php, you'd need something deeper than that.

    I don't know if .htaccess can be that long, and I can't think of a way around it by using two sets of .htaccess files or something. That isn't my area of expertise.

    Also, I just thought about virtual domain forwarding where you own the domain, but forward to another account. In that scenario,
    domain.com/stuff
    would be transferred to
    freehost.com/yourpage/stuff
    so... using that same theory, you could do the same thing. However, it would be weird as you'd want other things NOT to redirect and you'd want to link to the same domain. But it might point you in a direction where you can find some good info.


    Additionally, usually giving someone a domain would mean domain, not subdirectory.
    If you were to use theirname.domain.com as the address, that might help somehow too. I've seen plenty of hosts use something like that that masks something. For example, my host allows me to setup a subdomain like that that redirects to the identically named top level directory within the domain, like a.domain.com is just a mask for domain.com/a.
    Perhaps this is helpful.


    Now, of course, the less fancy way of doing all this would be to create a redirect page for each user. You could do it automatically using php during the signup process. Just have it create a folder for them and some type of redirect, such as a page with php and an http header redirect, or perhaps some type of .htaccess in there (though, again, I wouldn't know about this)
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  4. #4
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by 4bidden
    I'd like users to have their own easy to access URL when signing up for my service (i.e. domain.com/username).
    You should be careful with that. It's quite possible that a visitor will register with a name that you might, in the future, want to use to structure the site. Similarly, you'd need to check that any new names don't conflict with existing paths used by the site.

    The tilde (~) prefix is a common way to prevent clashes. A "users" path segment (/users/username/) is another alternative. A "users" domain is also possible (//users.example.com/username/).

    My first thought would be a .htaccess file...but just how big can a htaccess file be?
    There's no physical limit, but there is a practical one. Distributed configuration files (.htaccess) are read whenever the server accesses the directory in which they're located, or any subdirectories. For example, accessing "/foo/bar/file" will cause the server to scan any .htaccess files in "/", "/foo/", and "/foo/bar/".

    Modifying the main server configuration is typically preferable as that is only read once when the server is started. You should also be aware that URL rewriting is very limited when used in .htaccess files.

    I would suggest that you read the Apache .htaccess tutorial for more information.

    We're talking thousands of users. I'd estimate the htaccess being about 300KB doing this.
    If you use a pattern, such as one suggested earlier, then you should only need one set of rules.

    Sample situation
    User signs up under name "rider45"
    User is assigned the URL domain.com/rider45
    URL domain.com/rider45 needs to really point to something like domain.com/profiles/profile.php?user=rider45
    Do you want to make that an internal rewrite? That is, the user would not be redirected, only the server would be.


    Quote Originally Posted by djr33
    domain.com?user
    domain.com/?user
    The latter is the canonical representation of the former. In fact, paths are not allowed to be empty in HTTP URIs.

    domain.com/page.php/user (*might work*)
    The trailing part "/user" would be accessible from the PATH_INFO element in the $_SERVER superglobal array. I seem to remember that featuring in bug reports in the past, though. Still, it works fine here (PHP 5.2RC2 module, Apache 2.2.3, WinXP).

    The other way I can think of doing this would be to actually create a custom error page, and have that page use php then redirect based on the request URI.
    Absolutely not. Error conditions should only be used for actual errors. Not doing so is not only abuse of the protocol, but will also play havoc with clients that pay particular attention to the response code (such as search bots).

    Mike

  5. #5
    Join Date
    Dec 2005
    Location
    Tempe, AZ
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I need basically the same setup like MySpace has (no, the site is not related at all, my site is automotive) where you pick your domain name (myspace.com/xxxxx).

    There has got to be a very simple way of doing this? I really would like to stay away from using something like domain.com/users/username/ and domain.com/?username.

    The site is on a vps if it matters.

  6. #6
    Join Date
    Oct 2006
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I need help with the same issue

  7. #7
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Using php, you can do the above options.

    I'm not sure about other things.

    Look into php/cgi/etc to create the directories and index pages therein.

    Not sure what to tell you.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •