Implementation of URL rewrite Technology in Apache

Source: Internet
Author: User

Recently, our company's website is being optimized. If we want to adopt a better technology, we can make it easier for Google and other search engines to generate dynamic php web files, at present, we have adopted some improvement methods: for example, using PHP in the backgroundProgramChange the original file to the HTM content. The Apache path_info technology is used, but it is not powerful enough. Therefore, we decided to use the URL rewrite Technology in Apache to try it out.

I noticed it for a long time, but I still don't know how to implement it. Today I bit my teeth and flipped through N Articles.ArticleFinally, some basic functions are implemented:

1. Modify HTTP. conf

Under the root directory of the website you want to modify:

Defaulttype application/X-httpd-PHP
Rewriteengine on # required
Options followsymlinks # required
Rewriterule/news/(/d +)/. html/news/. php /? Id = $1 [n, l] # rule
AllowOverride all

2. Modify HTTP. conf first.

Defaulttype application/X-httpd-PHP
Options followsymlinks
AllowOverride all

Create a. htacess file in this directory. Its content is as follows:
Rewriteengine on
Rewritebase/websamples/urlrewrite/
Rewriterule news/(/d +)/. html news/. php /? Id = $1 [n, l]

 

This resolves http: // localhost/news/1000.html to http: // localhost/news. php? Id = 1000

Appendix: (a website's. htacess file)

-------------------------------------------------------------------------------

Errordocument 401/error. php
Rewriteengine on
Rewritebase/websamples/urlrewrite/power-for-less.com/

# Show category
#
Rewriterule ^ (laptop ([^/] *) | (camcorder ([^/] *) | (digital )?).? Camera ([^/] *) | (Power ([^/] *) | (PDA ([^/] *) | (mobile ([^/] *) | (two-way ([^/] *) | (rotate ([^/] *) | (MP3 ([^/] *)/. htm (L ?) $ Babrand/. php /? Fclassname = $1 [Nc]

# Show brands
#
Rewriterule ^ (laptop ([^/] *)/([^/] +)/. htm (L ?) $ Series/. php /? Fclassname = $1 & fb_babrand = $3 [Nc]
Rewriterule ^ (camcorder ([^/] *)/([^/] +)/. htm (L ?) $ Series/. php /? Fclassname = $1 & fb_babrand = $3 [Nc]
Rewriterule ^ (digital )?).? Camera ([^/] *)/([^/] +)/. htm (L ?) $ Series/. php /? Fclassname = $1 & fb_babrand = $5 [Nc]
Rewriterule ^ (Power ([^/] *)/([^/] +)/. htm (L ?) $ Series/. php /? Fclassname = $1 & fb_babrand = $3 [Nc]
Rewriterule ^ (PDA ([^/] *)/([^/] +)/. htm (L ?) $ Series/. php /? Fclassname = $1 & fb_babrand = $3 [Nc]
Rewriterule ^ (mobile ([^/] *)/([^/] +)/. htm (L ?) $ Series/. php /? Fclassname = $1 & fb_babrand = $3 [Nc]
Rewriterule ^ (two-way ([^/] *)/([^/] +)/. htm (L ?) $ Series/. php /? Fclassname = $1 & fb_babrand = $3 [Nc]
Rewriterule ^ (random ([^/] *)/([^/] +)/. htm (L ?) $ Series/. php /? Fclassname = $1 & fb_babrand = $3 [Nc]
Rewriterule ^ (MP3 ([^/] *)/([^/] +)/. htm (L ?) $ Series/. php /? Fclassname = $1 & fb_babrand = $3 [Nc]

# Show Products
#
Rewriterule ^ (laptop ([^/] *)/([^/] +)/(. +)/. htm (L ?) $ Product/. php /? Fclassname = $1 & fb_babrand = $3 & code = $4 [Nc]
Rewriterule ^ (camcorder ([^/] *)/([^/] +)/(. +)/. htm (L ?) $ Product/. php /? Fclassname = $1 & fb_babrand = $3 & code = $4 [Nc]
Rewriterule ^ (digital )?).? Camera ([^/] *)/([^/] +)/(. +)/. htm (L ?) $ Product/. php /? Fclassname = $1 & fb_babrand = $3 & code = $6 [Nc]
Rewriterule ^ (Power ([^/] *)/([^/] +)/(. +)/. htm (L ?) $ Product/. php /? Fclassname = $1 & fb_babrand = $3 & code = $4 [Nc]
Rewriterule ^ (PDA ([^/] *)/([^/] +)/(. +)/. htm (L ?) $ Product/. php /? Fclassname = $1 & fb_babrand = $3 & code = $4 [Nc]
Rewriterule ^ (mobile ([^/] *)/([^/] +)/(. +)/. htm (L ?) $ Product/. php /? Fclassname = $1 & fb_babrand = $3 & code = $4 [Nc]
Rewriterule ^ (two-way ([^/] *)/([^/] +)/(. +)/. htm (L ?) $ Product/. php /? Fclassname = $1 & fb_babrand = $3 & code = $4 [Nc]
Rewriterule ^ (random ([^/] *)/([^/] +)/(. +)/. htm (L ?) $ Product/. php /? Fclassname = $1 & fb_babrand = $3 & code = $4 [Nc]
Rewriterule ^ (MP3 ([^/] *)/([^/] +)/(. +)/. htm (L ?) $ Product/. php /? Fclassname = $1 & fb_babrand = $3 & code = $4 [Nc]

 

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.