Rewritecond is just like the IF statement in our program, which means that if one or more of the conditions are met, then the Rewriterule statement below Rewritecond is executed, which is the most primitive and basic function of rewritecond, to facilitate understanding, Let's look at a few examples below.
Copy Code code 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 access the index.php file using the FF browser, you will automatically be able to access the file index.m.php, when you are accessing it with some mobile terminals, Will let you actually visit index.php This file access is index.l.php to go, if you are using other browser to visit, will let you jump to index.b.php. In saying the image point, the above statement is equivalent to the following statement in the program
(as an example of PHP statements):
Copy Code code as follows:
if ($_server[' http_user_agent '] = = ' mozilla/5.0 ')
{
Jump to access to index.m.php
}
else if ($_server[' http_user_agent '] = = ' Lynx ')
{
Jump 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 are visiting is www.test.cn, then whatever page you are currently accessing will jump to the test.php access.
in the example three:
Copy Code code 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 test.php if your address is host1 or host2 or HOST3. It can be seen from here that the default is and between the rewritecond statements, and if you want to, explicitly write them.
Here are some useful rewrite rules for your favorites:
Rewritecond%{request_filename}!-f//If the file exists, direct access to the file 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) $//#如果是这些后缀的文件, direct access to files without rewrite