Apache rewrite example set

Source: Internet
Author: User
Tags webhosting

Apache rewrite example set
Forward one domain name to another in httpd
The VM domain name has recently changed. The new domain name is
Www.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
Serveradmin
Admin@webhosting-world.com
DocumentRoot/path/to/webhosting-World/root
Servername
Www.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/. com
Http://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]

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.