伪静态访问 简单代码实现案例

信息页面

<?php

    header("content-type:text/html;charset=utf8");
    $pdo=new PDO("mysql:host=localhost;dbname=exam",'root','root');
    $pdo->exec("set names utf8");
    //var_dump($arr);
    //搜索后分页
    $sea=isset($_REQUEST['sea'])?$_REQUEST['sea']:'';
    //总条数
    $res=count($pdo->query("select * from hao")->fetchAll(PDO::FETCH_ASSOC));
    //echo $res;die;
    //每页显示的条数
    $num=8;
    //总共分多少页
    $ye=ceil($res/$num);
    //echo $ye;die;
    //当前页
    $page=isset($_GET['page'])?$_GET['page']:1;
    //偏移量
    $pian=($page-1)*$num;
    //上一页
    $prev=$page<=1?1:$page-1;
    //下一页
    $next=$page>=$ye?$ye:$page+1;
    $arr=$pdo->query("select * from hao where title like '%$sea%' limit $pian,$num")->fetchAll(PDO::FETCH_ASSOC);
?>
<center>
<form action="" method="post">
<input type="text" name="sea">
<button>搜索</button>
</form>
<table border="1">
    <tr>
        <td>编号</td>
        <td>地址</td>
        <td>标题</td>
    </tr>
    <?php foreach ($arr as $k => $v) { ?>
    <tr>
        <td><?php  echo  $v['id'] ?></td>
        <td><?php  echo  $v['li'] ?></td>
        <td><?php  echo  $v['title'] ?></td>
    </tr>
    <?php    }  ?>
</table>
<a href="1_<?php echo $sea ?>.html">首页</a>
<a href="<?php echo $prev  ?>_<?php echo $sea ?>.html">上一页</a>
<a href="<?php echo $next  ?>_<?php echo $sea ?>.html">下一页</a>
<a href="<?php echo $ye  ?>_<?php echo $sea ?>.html">末页</a>

</center>

2..htaccess页面的代码实现(根目录创建文件)

 #开启重写引擎
RewriteEngine on
#配置重写规则
RewriteRule  seven7/Index.html  seven7/index.php [L,NC]
RewriteRule  test       seven7/test.php [L,NC]
#RewriteRule index.html      seven7/1412phpB/20160914/index.php [L,NC]
#分页的伪静态配置
RewriteRule    (\d+)_(.*)?.html           seven7/1412phpB/20160917/index.php?page=$1&sou=$2 [L,NC]
RewriteRule    index.html           seven7/1412phpB/20160917/index.php  [L]
#防盗链
ReWriteCond  %{HTTP_REFERER} !^$    [NC]
ReWriteCond  %{HTTP_REFERER} !http://www.study.com.*  [NC]
#RewriteRule    .*\.(jpeg|png|gif)$    -[F]
RewriteRule    .*\.(jpeg|png|gif|jpg)$     110.gif  [L]


#容错处理,当访问不存在的页面时友好提示
ReWriteCond  %{REQUEST_FILENAME} !-d
ReWriteCond  %{REQUEST_FILENAME} !-f
ReWriteRule  .*     404.html   [L]

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值