View Full Version : creating virtual user folders
4bidden
09-14-2006, 07:46 AM
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.
4bidden
09-27-2006, 04:07 AM
Nobody?
djr33
09-27-2006, 08:11 AM
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)
mwinter
09-27-2006, 12:13 PM
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 (http://httpd.apache.org/docs/2.2/howto/htaccess.html) 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.
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
4bidden
10-03-2006, 10:10 PM
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.
hughra
10-17-2006, 01:45 AM
I need help with the same issue
djr33
10-17-2006, 03:45 AM
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.
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.