I used rewrite several times, but I didn't use many times. I forgot to use it each time. I had to find a bunch of items on the Internet and summarize them to avoid forgetting it later.
================================== Separator ========================== ===
Note the following:
1. Load the rewrite module, loadmodule rewrite_module modules/mod_rewrite.so
2. If it is configured in vhost, open rewriteengine on in vhost (the htaccess file configuration method has not been used)
Used configurations:
Scenario 1: When the domain name is AAA. BBB, jump to the domain name AAA. ccc. bbb
Rewriteengine on
Rewritecond % {http_host} ^ AAA \. BBB $ [Nc]
Rewriterule ^/(. *) $ http://aaa.ccc.bbb/3691 [R = 301, L, NC]
% {Http_host} matches the domain name. ^ indicates that the match starts, and $ indicates that the match ends. They are the left and right sides of the match string. They can appear at different times ,\. escape, match only ., otherwise it will become any single character.
NC (no case) is case insensitive,
. Is any single character ,. * Any number of arbitrary characters, () is a sub-string, so ^ /(. *) $ indicates any path after the domain name. Here we guess we can omit $, here ., \ escape is not used because this part is not a regular expression. $1 matches the content in the first (). R = 301 indicates permanent jump,
Scenario 2: transfer the/testt/request to/image/, but the/testt/xxxx request does not jump.
Rewriteengine on
Rewriterule ^/testt/$ http: // localhost: 8000/image/[R = 301, L, NC]
================================== Separator ========================== ===
References:
The meaning of various characters in regular expressions http://www.cnblogs.com/afarmer/archive/2011/08/29/2158860.html
Apache rewrite rule usage instructions http://www.jb51.net/article/48780.htm
13 practical Apache rewrite rule http://www.jb51.net/article/47907.htm
Basics of Apache rewrite Regular Expressions