What're those lines meaning?

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.



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

Finally, you know where to find my tutorial and there are links to “cheat sheets” if you can’t find the information there. :nono:



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?


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?



got it, many thanks. my dear friend.dklynn

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 :slight_smile: