首先得保證apache已經安裝了mod_perl模塊,具體安裝配置可以看上一篇文章哦。
修改下http.conf配置,添加一下內容:
PerlTransHandler MyTrans # MyTrans 這個是自己添加的處理模塊名
具體MyTrans.pm腳本如下:
package MyTrans;
use strict;
use Apache2::Const qw(DECLINED);
sub handler {
my $r = shift;
my $uri = $r->uri;
my ($id) = ($url =~ m|^/news/(.*)/.html|);
$r->uri("/news.php");
$r->args("id=$id");
return Apache2::Const::DECLINED;
}
1;
實現就是:/news/12345.html => /news.php?id=12345