SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Member
    Join Date
    Oct 2007
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Odd mod_rewrite issue

    Hi everyone,

    I'm coming across this weird RewriteRule issue and don't know how to remedy it.

    Although mod_rewrite works like I want it to on other directories in my site, when I try to write the simple rule below, the GET variable is not stored.

    Code:
    RewriteRule ^account/([a-z]+)$ account.php?mod=$1 [NC]
    After messing around with the code a bit, I realized that what is seeming to cause the rule not to function correctly are the 2 "account" strings. It seems that whenever those two are the same, the rule does not work, but, if they are different, it does.

    Does anyone know how I can fix this? Any help is appreciated! Thanks!

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

    The "two account settings" would make no difference (they are not the same).

    No Case? In preference to the Last Flag? I'll bet the preceding RewriteRule was not terminated by a Last flag (either) so this RewriteRule is being ANDed with it, thus, it'll never match.

    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 Member
    Join Date
    Oct 2007
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is the only rule in the file, so I'm not sure that that is the case..

    What I meant by the two strings is that when they are the same (like above), the rule does not work. However, when they are different, like so, the rule functions correctly.

    Code:
    RewriteRule ^account/([a-z]+)$ accounts.php?mod=$1 [NC]
    Thanks for your reply!

  4. #4
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    8,907
    Mentioned
    139 Post(s)
    Tagged
    2 Thread(s)
    What DK meant is you should replace [NC] (which is not needed for your .htaccess) with [L]

    And, it sounds like you're having trouble with MultiViews. Try adding Options -MultiViews to the .htaccess:

    Code:
    Options -MultiViews
    
    RewriteEngine On
    RewriteRule ^account/([a-z]+)$ account.php?mod=$1 [L]
    Rémon - Hosting Advisor

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

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

    Yes, Options -MultiViews is something that I consider important as it would force Apache to fetch the file rather than the directory for accounts. As a part of the Apache core, that would take precedence over your mod_rewrite.

    Then, the differrence between "the two account strings" is that you are redirecting ^{start} followed by 'account' followed by / followed by {one or more lowercase letters} followed by NOTHING. That's being redirected to account.php with the key mod being assigned a value of {the one or more lowercase letters}. Please note, though, that by creating a new query string, it's killing any pre-existing query string, too.

    If that's not clear enough, please show your TEST URIs.

    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

  6. #6
    SitePoint Member
    Join Date
    Oct 2007
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The Options -MultiViews worked like a charm! Thanks to both DK and Scallio for your help!

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

    Aw, shucks!

    ScallioXTX gets all the credit for this one, though, as I didn't even consider that this was a MultiViews problem until he mentioned it.

    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
  •