Discover Habbo's history
Treat yourself with a Secret Santa gift.... of a random Wiki page for you to start exploring Habbo's history!
Happy holidays!
Celebrate with us at Habbox on the hotel, on our Forum and right here!
Join Habbox!
One of us! One of us! Click here to see the roles you could take as part of the Habbox community!


Results 1 to 9 of 9
  1. #1
    Join Date
    Oct 2007
    Posts
    824
    Tokens
    71

    Latest Awards:

    Default [PHP/HTACCESS] URL Help

    How do I make URL's like www.mysite.com/user/USERNAME? I have a usersystem and instead of doing www.mysite.com/users.php?user=USERNAME, I want the folder type URLs.
    Vouches
    [x][x]

  2. #2
    Join Date
    May 2006
    Location
    Hull
    Posts
    7,701
    Tokens
    2,430
    Habbo
    Moh

    Latest Awards:

    Default

    I always get myself muddled up with HTACCESS for some reason

    But something like this should work, I don't have access to our server atm though, so I cannot test it out.

    PHP Code:
    RewriteEngine On
    RewriteRule 
    ^user/([a-zA-Z0-9=_.!-]+)/$ users.php?user=$[NC

  3. #3
    Join Date
    Feb 2006
    Location
    Scotland
    Posts
    2,087
    Tokens
    138

    Latest Awards:

    Default

    This should help: http://www.habboxforum.com/showthread.php?t=514476

    This should work, just modified the code that Source posted:

    Code:
    RewriteEngine on
    RewriteRule ^user/([A-Za-z0-9-]+)/?$ users.php?user=$1 [L]
    EDIT: Looks like Jack bet me to it!

  4. #4
    Join Date
    Oct 2007
    Posts
    824
    Tokens
    71

    Latest Awards:

    Default

    Thanks I'll try it out.
    Vouches
    [x][x]

  5. #5

    Default

    I could see why you would add the last rule flag but on Jacks he uses the case insensitive flag when he's defining both lower and upper case letters.. Just doing extra work, mine was.
    Code:
    RewriteRule ^user/([^/]+)/?$ users.php?user=$1
    I'm sure you could also do something like.
    Code:
    RewriteRule ^user/(.+?)/?$ users.php?user=$1

  6. #6
    Join Date
    Nov 2007
    Posts
    1,253
    Tokens
    150

    Latest Awards:

    Default

    The easiest way to do it is with custom routes for each url type (as shown above).

    The other option is to redirect everything to index.php (or a php file to handle it) and then use php to handle it; this option, however, is only normally used with frameworks.

  7. #7
    Join Date
    Oct 2007
    Posts
    824
    Tokens
    71

    Latest Awards:

    Default

    Okay now there are so many suggestions I don't know which to use.

    I want the following:
    -Trailing slash is optional
    -users.php?user=USERNAME becomes users/USERNAME
    -The USERNAME part cannot have any slashes (other than the beginning and trailing slash)
    Vouches
    [x][x]

  8. #8
    Join Date
    Mar 2008
    Posts
    5,108
    Tokens
    3,780

    Latest Awards:

    Default

    Quote Originally Posted by Iszak View Post
    I could see why you would add the last rule flag but on Jacks he uses the case insensitive flag when he's defining both lower and upper case letters.. Just doing extra work, mine was.
    Code:
    RewriteRule ^user/([^/]+)/?$ users.php?user=$1
    I'm sure you could also do something like.
    Code:
    RewriteRule ^user/(.+?)/?$ users.php?user=$1
    It wouldn't be a plus though would it? I thought it was (.*?) for non greedy matches?

  9. #9

    Default

    They're both non-greedy, the difference is .* matches zero or more where as .+ matches one or more.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •