SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2012
    Posts
    69
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    rewrite rule for including the username?

    alright so im starting to get the understand the extremely complicated art of rewriting urls.
    i want to be able to make a url have the users username in it before the page that they are on when they are logged in. What i mean is this:
    http://sameple.com/user/home
    how do i make it so that their username goes where user is instead of a plain url like what i would have now when they're logged in: http://sameple.com/home.php

  2. #2
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,644
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    caleb,

    mod_rewrite is all about logic. If you understand the logic of 0 and 1, you'll pick-up on mod_rewrite quickly (try the tutorial linked in my signature).

    Pseudo code:

    If a file request does not exist AND
    if the file exists without the first directory (member name)
    capture the filename and redirect there.

    With the sample code in the tutorial and the above pseudo code, you should be able to create the correct code. If not, show me what you've attempted and I'll get you there.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  3. #3
    SitePoint Enthusiast
    Join Date
    Jul 2012
    Posts
    69
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    okay, i went through the tutorial and i have a question about the pseudo code. what do you mean if a file request does not exist?

  4. #4
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,644
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    caleb,

    If the file requested by a visitor does not exist (i.e., a 404 request), use RewriteCond %{REQUEST_FILENAME} !-f. The AND is implied between this RewriteCond and the next RewriteCond or RewriteRule's regex.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator


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
  •