Results 1 to 9 of 9

Thread: URL's and htaccess maybe

  1. #1

    Thread Starter
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    URL's and htaccess maybe

    I want to have a url like "http://www.mysite.com/mypage". the "mypage" is going to be different for every user. It may also be a number.

    My question, how do i make it so it will do that, and to check if it is a name or a number. ex:


    URL:: mysite.com/dclamp
    Actual Page: mysite.com/view_profile.php?id=dclamp

    URL:: mysite.com/13
    Actual Page: mysite.com/view_profile.php?id=13

    EDIT:
    i dont want to redirect it.
    Last edited by dclamp; Jun 17th, 2007 at 06:02 PM. Reason: Edited URLS
    My usual boring signature: Something

  2. #2
    Fanatic Member McCain's Avatar
    Join Date
    Jan 2002
    Location
    Sweden/Denmark
    Posts
    802

    Re: URL's and htaccess maybe

    The standard way of doing something like that is using mod_rewrite http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html
    Never argue with fools, they will only drag you down to their level, and beat you with experience.

    Q: How do you tell an experienced hacker from a novice?
    A: The latter thinks there's 1000 bytes in a kilobyte, while the former is sure there's 1024 meters in a kilometer

  3. #3

    Thread Starter
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: URL's and htaccess maybe

    ok thanks, now i need help with mod_rewrite :P. i suck at regular expressions...
    My usual boring signature: Something

  4. #4
    Fanatic Member McCain's Avatar
    Join Date
    Jan 2002
    Location
    Sweden/Denmark
    Posts
    802

    Re: URL's and htaccess maybe

    I have never used it myself, but there are lots of guides/tutorials on how to use it...
    Never argue with fools, they will only drag you down to their level, and beat you with experience.

    Q: How do you tell an experienced hacker from a novice?
    A: The latter thinks there's 1000 bytes in a kilobyte, while the former is sure there's 1024 meters in a kilometer

  5. #5
    Frenzied Member
    Join Date
    Jun 2005
    Posts
    1,170

    Re: URL's and htaccess maybe

    Hm... this is an interesting topic, anyone else provides a "help?"

  6. #6
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: URL's and htaccess maybe

    To redirect by user IDs or name differently, you need two rules:
    Code:
    RewriteEngine On
    RewriteRule ^([0-9]+)$ files/view_profile.php?id=$1 [L]
    RewriteRule ^([0-9A-Za-z_]+)$ files/view_profile.php?name=$1
    Note that the second of those will only allow user names containing characters that are alphanumeric or underscores. You may want to add additional characters. However, don't add a dot (\.) as that will cause rewriting to take place on URIs for things like images and CSS/script files.

  7. #7

    Thread Starter
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: URL's and htaccess maybe

    well i think i will have it so the var id will be for both name and id number, then i will do the checking in php,

    what do i need to change in your code?
    My usual boring signature: Something

  8. #8

    Thread Starter
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: URL's and htaccess maybe

    this .htaccess file was used for the other script i used to use, can some one translate it for me :P

    Code:
    RewriteEngine  on
    RewriteBase    /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ view_profile.php?member_id=$1
    My usual boring signature: Something

  9. #9
    Fanatic Member McCain's Avatar
    Join Date
    Jan 2002
    Location
    Sweden/Denmark
    Posts
    802

    Re: URL's and htaccess maybe

    In this line: RewriteRule ^(.*)$ view_profile.php?member_id=$1
    ^ matches the start of the string. $ matches the end of the string and (.*) matches and captures anything in between. The $1 at the end of the string gets replaced with whatever (.*) captured
    Never argue with fools, they will only drag you down to their level, and beat you with experience.

    Q: How do you tell an experienced hacker from a novice?
    A: The latter thinks there's 1000 bytes in a kilobyte, while the former is sure there's 1024 meters in a kilometer

Posting Permissions

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



Click Here to Expand Forum to Full Width