SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Evangelist runeveryday's Avatar
    Join Date
    Jul 2009
    Posts
    437
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    what're those lines meaning?

    Code:
    RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
    RewriteCond %1/%{REQUEST_FILENAME} -f
    RewriteCond %1/%{REQUEST_FILENAME} -d
    RewriteRule index.php?=%{REQUEST_FILENAME} [L]
    after read some apache rewrite documentation, i have know some basic knowledge, but still can't understand some part of the above lines well.

    %{HTTP_HOST} the requset domain

    [NC] (case insensitive)

    L (last - stop processing rules)

    -f if Something_to_test is a file

    -d if Something_to_test is a directory

    %{REQUEST_FILENAME} the requset file name

    1, what's the $ meaning in (^www\.(.*)$). all the url that requested by the client are all beginning by www. . am i right?

    2,what's the meaning %1/% ?

    3,RewriteRule index.php?=%{REQUEST_FILENAME}

    if the three RewriteCond are all right, it will execute the RewriteRule ?what's the meaning of it. thank you.

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    So you're that guy on StackOverflow...

    Did you read the mod_rewrite documentation as suggested? What about a regex tutorial for the meaning of $?

    You got a line-by-line explanation of what that code means and why it's not good.

    http://stackoverflow.com/questions/6...-lines-meaning

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

    RED has been here before and English is not his first language.

    Quote Originally Posted by runeveryday View Post
    Code:
    RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
    RewriteCond %1/%{REQUEST_FILENAME} -f
    RewriteCond %1/%{REQUEST_FILENAME} -d
    RewriteRule index.php?=%{REQUEST_FILENAME} [L]
    after read some apache rewrite documentation, i have know some basic knowledge, but still can't understand some part of the above lines well.

    %{HTTP_HOST} the requset domain

    [NC] (case insensitive)

    L (last - stop processing rules)

    -f if Something_to_test is a file

    -d if Something_to_test is a directory

    %{REQUEST_FILENAME} the requset file name

    1, what's the $ meaning in (^www\.(.*)$). all the url that requested by the client are all beginning by www. . am i right?
    $ is the END_OF_STRING marker just as ^ is the START_OF_STRING marker.
    2,what's the meaning %1/% ?
    To access Apache variables, they must be preceded by the % character (just as PHP variables are preceded with a $). In your question, %1 is the first atom created in the associated RequestCond statements, the / a directory marker and %{REQUEST_URI} is Apache's {REQUEST_URI} variable.
    3,RewriteRule index.php?=%{REQUEST_FILENAME}
    Without regex, this will cause a 500 error from the server; with regex, no matter what, the lack of a key for the value of the URI, makes any result is meaningless (except for the redirection to index.php). In fact, you've required the {REQUEST_FILENAME} to be both a file AND a directory so you will never execute the meaningless RewriteRule (except to throw the 500 error).
    if the three RewriteCond are all right, it will execute the RewriteRule ?what's the meaning of it. thank you.
    Finally, you know where to find my tutorial and there are links to "cheat sheets" if you can't find the information there.

    Regards,

    DK
    Last edited by dklynn; Jul 30, 2011 at 03:03. Reason: regex lacking; file/directory tests ANDed => FALSE
    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

  4. #4
    SitePoint Evangelist runeveryday's Avatar
    Join Date
    Jul 2009
    Posts
    437
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    many thanks. i have understood question one and two.

    but there is still some part which i can't follow well.

    why access the {REQUEST_FILENAME} make the RewriteRule meaningless?

    someone told me that this line is wrong:RewriteRule index.php?=%{REQUEST_FILENAME} [L] , i should add ^ before the index.php....
    but i don't know why?

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

    The {REQUEST_FILENAME} cannot be both a file and a directory and, unless the OR flag is used, they are ANDed resulting in a FALSE every time. Simple logic, my friend.

    What I'd said about[code]RewriteRule index.php?=%{REQUEST_FILENAME} [L][code]is that it is lacking the required FORMAT for the RewriteRule directive, i.e., RewriteRule, regex, redirection and optional flags. WHERE IS YOUR REGEX?

    Didn't I explain both of those well enough above?

    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 Evangelist runeveryday's Avatar
    Join Date
    Jul 2009
    Posts
    437
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    got it, many thanks. my dear friend.dklynn

  7. #7
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,085
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by runeveryday View Post
    Code:
    L (last - stop processing rules)
    Nope. The [L] flag means "Stop this rewrite round and start a new one, processing all RewriteRules again from the top.".
    There's a subtle difference
    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

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


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
  •