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]