Apache in the Rewritecond statement for me has been a difficult point, many attempts to understand it, there is no structure, this time I finally figured out what it means.
Rewritecond, like the IF statement in our program, means that if one or a few conditions are met, the Rewriterule statement immediately below the Rewritecond is executed, which is Rewritecond's most primitive and basic function, for convenience of understanding, Let's look at a few examples below.
Copy CodeThe code is as follows:
Rewriteengine on
Rewritecond%{http_user_agent} ^mozilla//5/.0.*
Rewriterule index.php index.m.php
Rewritecond%{http_user_agent} ^lynx.*
Rewriterule index.php Index. l.php
Rewriterule index.php index.b.php
The function of the above statement is that when you use the FF browser to access index.php This file, it will automatically let you access to index.m.php this file, when you are using some mobile terminal access, will give you access to index.php this file is the actual access to the index.l.php, if you are in another browser access, will let you jump to index.b.php. In the image, the above statement is equivalent to the following statement inside the program (in the case of PHP statements):
Copy CodeThe code is as follows:
if ($_server[' http_user_agent '] = = ' mozilla/5.0 ')
{
Jump to access to index.m.php
}
else if ($_server[' http_user_agent '] = = ' Lynx ')
{
Jumps to the index. L.php's visit
}
Else
Jump to access to index.b.php
In See Example 2:
Rewritecond%{http_referer} (www.test.cn)
Rewriterule (. *) $ test.php
The function of the above statement is that if the host address of the previous page you access is www.test.cn, then regardless of which page you are currently accessing, you will be redirected to access to test.php.
In See example three:
Copy CodeThe code is as follows:
Rewritecond%{remote_host} ^host1.* [OR]
Rewritecond%{remote_host} ^host2.* [OR]
Rewritecond%{remote_host} ^host3.*
Rewriterule (. *) $ test.php
The function of the above statement is to jump to the test.php if your address is host1 or host2 or HOST3. As can be seen here, the default between Rewritecond statements is and, if you want or, you have to explicitly write it.
Here are some of the useful rewrite rules for your collection:
Rewritecond%{request_filename}!-f//If the file exists, access the file directly without the following rewriterule. (Do not overwrite if file or file does not exist)
Rewritecond%{request_filename}!-d//#如果目录存在就直接访问目录不进行RewriteRule
Rewritecond%{request_uri}!^.* (/.css|/.js|/.gif|/.png|/.jpg|/.jpeg) $//#如果是这些后缀的文件, directly access the file without rewrite
http://www.bkjia.com/PHPjc/372370.html www.bkjia.com true http://www.bkjia.com/PHPjc/372370.html techarticle Apache Rewritecond Statements for me has always been a difficult point, many times trying to understand it, there is no structure, this time I finally figured out what it means rewritecond like us ...