0

Hi, i working on a profile system, each users has their public profile and its directory is in http://website.com/username but the proble is that my root is gonna get a bit messy if all folders of each user is created ther, so i want to put all users folder in a folder name users, but then the url be like http://website.com/users/username

Is it posible to some how when enter http://website.com/username still get the content of http://website.com/users/username

Thanks and sorry for my bad english

3
Contributors
5
Replies
33
Views
3 Years
Discussion Span
Last Post by centenond
1

Try making a file in the users folder that will select the right file. I'm assuming you're detecting username from a post variable. So users/users.php would have something like this:

if(isset($_POST['username']) && $_POST['username'] != ''){
    //include "users/username/profile.php"
    include_once('users/'.$_POST['username'].'/profile.php');
}

You'll want to add testing if the file exists before including or an error will be thrown if that file doesn't exist.

But keep in mind this will make the url http://website.com/users/users.php you'll need to take a look at the rewrite capabilities of .htaccess, but from what you're showing as links you've got that covered, i guess.

0

Try making a file in the users folder that will select the right file. I'm assuming you're detecting username from a post variable.

got the idea but im not detecting username from post, i would like to when they give their friends their url just be www.website.com/username guess i could get it like u say and use get instead like www.website.com?user=username but i think would be much cleaner just website/username like facebook

Tell me if i missunderstood , Thanks for reply

2

Hi, i working on a profile system, each users has their public profile and its directory is in http://website.com/username but the proble is that my root is gonna get a bit messy if all folders of each user is created ther, so i want to put all users folder in a folder name users, but then the url be like http://website.com/users/username

Is it posible to some how when enter http://website.com/username still get the content of http://website.com/users/username

Thanks and sorry for my bad english

This is a good scenario for using Apache's mod_rewrite module. With it you can manipulate the URL and where it actually goes.

In this case you want to redirect everything to the users directory. Below is an example of how to do that. It checks to make sure the request isn't an actual file or directory first. If it is then you'll serve that and not a file in the users directory.

<IfModule mod_rewrite.c>
    RewriteEngine On

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d

    RewriteRule ^(.*) /users/$1
</IfModule>

If the URL entered is (for example) http://domain.tld/someusername, this rewrite rule will actually serve http://domain.tld/users/someusername. The end-user will be none-the-wiser that their request is being modified internally.

0

Go with what Bob Hensley suggested, it's what I meant with:

But keep in mind this will make the url http://website.com/users/users.php you'll need to take a look at the rewrite capabilities of .htaccess, but from what you're showing as links you've got that covered, i guess.

You might want to look around for some tutorials on the mod_rewrite since it's a very powerful tool. With it, you can pass the url as if it was get variables but with the presentation you want, instead of redirecting to a different file. So you could actually pass in http://website.com/username and that url would be considered as http://website.com/users.php?username=username.

Also I think it will become cumbersome to have a file for each user, so try to find a way to make that dynamic, if possible. It will save you time in the future.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.