首先我们新建一个.htaccess文件之后,就在里面写入以下内容:
RewriteEngine on #rewriteengine为重写引擎开关on为开启off为关闭
RewriteRule ([0-9]{1,})$ index.php?id=$1
我讲解一下RewriteRule:RewriteRule是重写规则,支持正则表达式的,上面的([0-9]{1,})是指由数字组成的,$是结束标志,说明是以数字结束!
好吧,现在我们可以实现伪静态页面了,写下一下的规则:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ([a-zA-Z]{1,})-([0-9]{1,}).html$ index.php?action=$1&id=$2
</IfModule>
([a-zA-Z]{1,})-([0-9]{1,}).html$是规则,index.php?action=$1&id=$2是要替换的格式,$1代表第一个括号匹配的值,$2代表第二个,如此类推!!
我们写一个处理的PHP脚本:
index.php
<?php
echo ‘你的Action是:’ . $_GET['action'];
echo ‘<br/>’;
echo ‘你的ID是:’ . $_GET['id'];
?>
好了,我们现在在浏览器中输入:
localhost/view-12.html
输出的是:
你的Action是:view
你的ID是:12