Is it possible to format URL with PHP

Discussion in 'PHP' started by ketting00, Nov 30, 2010.

  1. #1
    I was wondering if it possible to format URL with PHP?

    I'm not sure if it the right question but I'm going to make it as clear as possible.

    I want to create a folder for every user that signed up on my website. But I don't want too much files in the root directory, so the have create them on folder [USERS].

    The problem is the URL will look like this: http://www.mywebsite.com/users/username/

    But I want them to look like this: http://www.mywebsite/username/

    Is it possible to achieve this with PHP?

    Thanks

    EDIT: On searching, there is something to to with the .htaccess file. But how to write it.
     
    Last edited: Nov 30, 2010
    ketting00, Nov 30, 2010 IP
  2. gapz101

    gapz101 Well-Known Member

    Messages:
    524
    Likes Received:
    8
    Best Answers:
    2
    Trophy Points:
    150
    #2
    yeah together with .htaccess

    RewriteRule ^([^\/]+)/? /users/$1 [NC,L]
     
    gapz101, Dec 1, 2010 IP
  3. Silph

    Silph Peon

    Messages:
    78
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    nvm guy above^
     
    Silph, Dec 1, 2010 IP
  4. koula

    koula Peon

    Messages:
    23
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Or rename folder users to username
     
    koula, Dec 1, 2010 IP
  5. techbongo

    techbongo Active Member

    Messages:
    309
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    80
    #5
    It's your choice whether you want to maintain separate physical folders for each user, or to implement the same functionality with Apache Mod Rewrite. In this I should say, most of the websites today, are implementing hierarchical URL structure by rewriting URLs, not by maintaining separate folder. This reduces the effort of web design, maintenance and the size of website.
     
    techbongo, Dec 1, 2010 IP
  6. ketting00

    ketting00 Well-Known Member

    Messages:
    782
    Likes Received:
    28
    Best Answers:
    3
    Trophy Points:
    128
    #6
    Thank techbongo

    I think I would choose the last choice you have suggested. I am still learning. I would go with that "implementing hierarchical URL structure by rewriting URLs" thing, because it sounds saving space and improving speed. But there's a dilemma of how to allot them use space though.
     
    ketting00, Dec 3, 2010 IP