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.
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/6880917/whatre-those-lines-meaning
dklynn
July 30, 2011, 9:59am
3
Dan,
RED has been here before and English is not his first language.
runeveryday:
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
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?
dklynn
July 31, 2011, 8:38am
5
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
RewriteRule index.php?=%{REQUEST_FILENAME} [L]
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
got it, many thanks. my dear friend.dklynn
rpkamp
August 3, 2011, 11:24pm
7
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