实现伪静态页面

1.建立.htaccess 文件
在网站文件夹根目录,比如我的是test
2.在该文件中添加rewrite规则:
 
RewriteEngine on
RewriteRule ([a-zA-Z]{1,})-([0-9]{1,})\.html$ index.php?action=$1&id=$2
 
其中:rewriteengine为重写引擎开关on为开启off为关闭
RewriteRule:RewriteRule是重写规则,支持正则表达式
([a-zA-Z]{1,})-([0-9]{1,})\.html$是规则,index.php?action=$1&id=$2是要替换的格式,$1代表第一个括号匹配的值,$2代表第二个,如此类推!!
 
3.新建上述规则的对应php文件(index.php)
<?php
echo '你的Action是:' . $_GET['action'];
echo '<br/>';
echo '你的ID是:' . $_GET['id'];
?>
 
4.浏览器输入localhost/test/view-12.html
可得如下结果:

猜你喜欢

转载自www.cnblogs.com/yyhfirstblog/p/11768140.html