PDA

View Full Version : User Pages - simple addressing


djmatt
11-04-2007, 04:04 PM
Hi,
I am going to develop a web site with lots of users who will have their own individual pages. I want a very simple address for them to give to their contacts like they use in myspace. For example:
www.my_space . com/my_page
The only way I can see to do this is to have a folder called "my_page" with index.php in it. However, I don't want hundreds of folders in my directory. Also, I don't want to have to delete someone's mysql and their folder, too time-consuming.

Is there a way to pull the user name from the above address and load their data? Or do I have have a folder for everyone?

Thanks.

Basil
11-04-2007, 06:55 PM
You make a rule like this..

RewriteRule ^([A-Za-z0-9-]+)/?$ whatever.php?user=$1

Then pull the variable using $_GET['user'] or something in the php file.

So your url looks like example.com/user, and the server forwards it to example.com/whatever.php?user=user.

example .htaccess file
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^([A-Za-z0-9-]+)/?$ whatever.php?user=$1

djmatt
11-05-2007, 09:08 AM
Thanks. That was driving me nuts. That works so well.