SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Nov 2008
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    directories and variables

    I wonder if anyone will be able to point me in the right direction as i seem to be stuck. I think what i am trying to do is very simple yet i can't seem to figure it out.

    I was looking at mod_rewrite to do the job but can't seem to get that going. Most likely due to my inability that is why am asking you for some help.

    What i want to do is this. I have a website and each user will be assigned his/her own directory ie: domain.com/joe or domain.com/jenny

    what i would like to do is to use the directory name as a variable to poll data from the database. I could create a directory for each user .. but that would be just plain waste of space so i would have one file but each time the url would be entered it would use the so called directory as a variable.

    Does all this make sense at all ? i hope so and i hope someone can help me.

    Thank you in advance.

    Eggy

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There's many ways to go about this, but here's a simple one

    Put this in a .htaccess file
    Code:
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule .* script.php [L]
    Your php script can now parse $_SERVER['REQUEST_URI'] to get the needed info.

    That will map ALL requests to files or directories which don't exist to your script. This can be too much, as it now essentially gives this script the burden of being the 404 error page too. Solutions:
    Turn off rewriting in all other directorys, by placing another .htaccess file in each dir
    Code:
    RewriteEngine Off
    Otherwise, you will need to devise some type of pattern in the url which can be matched with a regular expression. Basically find the distinctions between these fake folder urls, and urls which actually map to a real file or dir.

  3. #3
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2006
    Location
    Augusta, Georgia, United States
    Posts
    4,139
    Mentioned
    16 Post(s)
    Tagged
    3 Thread(s)
    You may run into conflicting user names and page names if you go about it that way. For example, if a user is named about and you have a about page then domain.com/about wouldn't resolve correctly. I recommend you place user or something before which would resolve the problem. So instead of domain.com/jenny you would use domain.com/user/jenny.Then by the chance someone has the same name as a page you could could still access the page via domain.com/about.

    One of the ways to accomplish this is to rewrite the url in the .htaccess file. The below would essentially rewrite as you like to index of id in the $_GET array.

    Code:
    RewriteRule ^user/(.*?)$ /users.php?id=$1 [L]


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
  •