Apache rewrite module (URL rewriting module) Configuration

Source: Internet
Author: User

1. First, check whether the rewrite module is installed:

Cat httpd. conf | grep rewrite
Loadmodule rewrite_module modules/mod_rewrite.so

2. Generate a pseudo-static html connection:

(1) generate pseudo-static html

Add at the end of the <virtualhost> segment

Rewriteengine on
Rewriterule/goods(%0-9%%%%%.html/goods. php? Id = $1 [pt]
More standard writing:
Rewriterule ^ (. *)/goods(%0-9%%%%%.html $1/goods. php? Id = $2 [pt]
Simpler Syntax:
/Goods (\ D +) \. html/goods \. php \? Id = $1

The first parameter (0-9] +) corresponds to $1, and the second parameter corresponds to $2.

Example:

Rewriterule/Forum-([0-9] +)-([0-9] +) \. html/Forumdisplay. php? FID = $1 & page = $2 [pt]

Test http://www.xxx.com/goods1.html with/goods. php? The content of ID = 1 is the same

Finally, replace all links with the configured pseudo-static html address.

[Pt]: url, that is, the converted goods31.html corresponds to goods. php? Id = 31 (this parameter is not added by default)
[R]: The URL redirection jumps to goods. php when goods31.html is used for access? Id = 31

3. Anti-leech:

Rewritecrond % {http_host }! Upkiller.com [R = 301, l]
Rewriterule ^ (. *) $ http://www.upkiller.com/warning.html [R = 301, l]

Redirect requests not from upkiller.com to the http://www.upkiller.com/

Better practice:
Rewritecond % {http_referer }! ^ Http: // (www \.)? Upkiller \. com/. * $ [Nc]
Rewriterule \. (MP3 | RAR | jpe | GIF) $ http://www.upkiller.com/warning.jpg [R = 301, l]

4. Anti-Baidu crawler:
Rewritecond % {http_user_agent} ^ baiduspider [or]
Rewriterule ^ (. *) $ http://www.google.com/[R = 301, l]
Convert crawlers from Baidu to Goole

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.