Apache中URL Rewrite技术的实现
2007-06-14 19:14
447 查看
最近我们公司的网站在进行优化动作,要想采用一种好点的技术,使得原来的PHP动态形式的网页文件能够被GOOGLE等搜索引擎更加容易地收入其中,目前我们已经采用了一些改进办法:比如在后台用PHP程序将原来的文件改成HTM内容;采用Apache的Path_Info技术,但觉得还是不够强大,因此决定采用Apache中的URL Rewrite技术来试用一下。
很早就注意到它了,但一直不知道怎么实现,今天咬咬牙,翻了N篇有关的文章,终于实现了一些基本的功能:
1、修改http.conf
在你要修改网站的根目录下:
DefaultType application/x-httpd-php
rewriteengine on #必须
options followsymlinks #必须
RewriteRule /news/(/d+)/.html /news/.php/?id=$1 [N,L] #规则
AllowOverride All
2、先修改http.conf
DefaultType application/x-httpd-php
options followsymlinks
AllowOverride All
然后再在此目录下建立一个.htacess文件,它的内容如下:
rewriteengine on
rewritebase /websamples/urlrewrite/
RewriteRule news/(/d+)/.html news/.php/?id=$1 [N,L]
这样就实现了将http://localhost/news/1000.html 解析为 http://localhost/news.php?id=1000的功能
附录:(一个网站的.htacess文件)
-------------------------------------------------------------------------------
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]
很早就注意到它了,但一直不知道怎么实现,今天咬咬牙,翻了N篇有关的文章,终于实现了一些基本的功能:
1、修改http.conf
在你要修改网站的根目录下:
DefaultType application/x-httpd-php
rewriteengine on #必须
options followsymlinks #必须
RewriteRule /news/(/d+)/.html /news/.php/?id=$1 [N,L] #规则
AllowOverride All
2、先修改http.conf
DefaultType application/x-httpd-php
options followsymlinks
AllowOverride All
然后再在此目录下建立一个.htacess文件,它的内容如下:
rewriteengine on
rewritebase /websamples/urlrewrite/
RewriteRule news/(/d+)/.html news/.php/?id=$1 [N,L]
这样就实现了将http://localhost/news/1000.html 解析为 http://localhost/news.php?id=1000的功能
附录:(一个网站的.htacess文件)
-------------------------------------------------------------------------------
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]
相关文章推荐
- Apache中URL Rewrite技术的实现
- Apache中URL Rewrite技术的实现
- Apache中 URL Rewrite技术的实现
- Apache中URL Rewrite技术的实现
- Apache中URL Rewrite技术的实现
- 巧用PHP的header函数实现apache的虚拟主机技术
- 静态化 - 伪静态技术(Apache Rewrite 实现)
- rewrite 技术实现 Apache 防盗链
- Apache rewrite技术实现Apache到lighttpd迁移
- Apache Spark技术实战之7 -- CassandraRDD高并发数据读取实现剖析
- Apache 防盗链(Apache Anti-Leech)技术的简单实现
- Apache 防盗链(Apache Anti-Leech)技术的简单实现
- 使用 rewrite 技术实现 Apache 防盗链
- 应用Apache的rewrite技术 实现面向搜索引擎优化
- Apache rewrite技术实现Apache到lighttpd迁移(转)
- Apache 防盗链(Apache Anti-Leech)技术的简单实现
- Apache 防盗链(Apache Anti-Leech)技术的简单实现
- apache mod_perl实现 url rewrite
- (转) Apache rewrite技术实现Apache到lighttpd迁移