Apache rewrite example set
Forward one domain name to another in httpd
The VM domain name has recently changed. The new domain name isWww.wbhw.comTo make it easier to remember. In this case, you need to direct the original domain name webhosting-world.com, and the address of the Forum webhosting-world.com/forums/ to the new domain name, so that the user can find, and make the original Forum URL continue to be valid without 404 not found, for example, the originalHttp: // www. Webhosting-world.com/forums/-f60.html. Make it valid under the new domain name. Click it and forward itHttp://bbs.wbhw.com/-f60.htmlThis requires the mod_rewrite function of Apache.
Add the following redirection rules in <virtualhost>:
Rewriteengine on
# Redirect webhosting-world.com/forums to bbs.wbhw.com
Rewritecond % {request_uri} ^/forums/
Rewriterule/forums /(.*)Http://bbs.wbh?com/#1[R = permanent, l]
# Redirect webhosting-world.com to wbhw.com
Rewritecond % {request_uri }! ^/Forums/
Rewriterule /(.*)Http://www.wbh?com/#1[R = permanent, l]
After the above rules are added, all content in the rules is as follows:
<Virtualhost *: 80>
Serveralias webhosting-world.com
ServeradminAdmin@webhosting-world.com
DocumentRoot/path/to/webhosting-World/root
ServernameWww.webhosting-world.com
Rewriteengine on
# Redirect webhosting-world.com/forums to bbs.wbhw.com
Rewritecond % {request_uri} ^/forums/
Rewriterule/forums /(.*)Http://bbs.wbh?com/#1[R = permanent, l]
# Redirect webhosting-world.com to wbhw.com
Rewritecond % {request_uri }! ^/Forums/
Rewriterule /(.*)Http://www.wbh?com/#1[R = permanent, l]
</Virtualhost>
Example 1 of URL redirection:
1. http://www.zzz.com/xxx.php->Http://www.zzz.com/xxx/
2. http://yyy.zzz.com->Http://www.zzz.com/user.php? Username = yyyFunctions
Rewriteengine on
Rewritecond % {http_host} ^ www.zzz.com
Rewritecond % {request_uri }! ^ User/. php $
Rewritecond % {request_uri}/. php $
Rewriterule (. *)/. php $Http://www.zzz.com/4241/[R]
Rewritecond % {http_host }! ^ Www.zzz.com
Rewriterule ^ (. +) % {http_host} [c]
Rewriterule ^ ([^/.] +)/. Zzz/. comHttp://www.zzz.com/user.php? Username = $1
Example 2:
/Type. php? Typeid = * -->/type *. html
/Type. php? Typeid = * & page = * -->/type * page *. html
Rewriterule ^/type(%0-9%%%%%.html $/type. php? Typeid = $1 [pt]
Rewriterule ^/type(%0-9%%%%%%page(%0-9%%%%%%.html $/type. php? Typeid = $1 & page = $2 [pt]