Recently our company's website is in the optimization action, to adopt a better technology, so that the original PHP dynamic form of the Web page files can be Google and other search engines more easily revenue, we have adopted a number of improvements: for example, in the background with PHP program to change the original file to HTM content , using Apache Path_info technology, but feel still not strong enough, so decided to use Apache URL rewrite technology to try.
Very early attention to it, but has not known how to achieve, today bite teeth, turned the n article about the article, and finally realized some basic functions:
1. Modify Http.conf
In the root directory where you want to modify the site:
DefaultType application/x-httpd-php
Rewriteengine on #必须
Options FollowSymLinks #必须
rewriterule/news/(/d+)/.html/news/.php/?id=$1 [n,l] #规则
AllowOverride All
2. Modify Http.conf First
DefaultType application/x-httpd-php
Options FollowSymLinks
AllowOverride All
Then create a. htacess file in this directory, which reads as follows:
Rewriteengine on
rewritebase/websamples/urlrewrite/
Rewriterule news/(/d+)/.html news/.php/?id=$1 [n,l]
This enables the ability to parse http://localhost/news/1000.html into http://localhost/news.php?id=1000
Appendix: (A. htacess file for a Web site)
-------------------------------------------------------------------------------
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 ([^/]*)) | (Scanner ([^/]*)) | (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 ^ (Scanner ([^/]*))/([^/]+)/.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 ^ (Scanner ([^/]*))/([^/]+)/(. +)/.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]