伪静态优点::
- 最主要的是为了搜索引擎方便搜索引擎蜘蛛(Spider)来抓取主页上的相关内容
- 提高用户对主页的信任度
- 增加网站在搜索引擎的排名
- 方便用户访问网站
一个好网页如果是动态的用户在相互传播时感觉对方信任度不会高但一看一个静态页相对用户对网页的信任度就高点而且
liunx下伪静态实现::
一、Apache Rewrite的配置【查询phpinfo()里rewrite必须开启两项:mod_rewrite 和 url_rewriter.tags】
1、打开Apache的配置文件httpd.conf 【温馨提示:修改重要配置文件先备份呦^.^】
#LoadModule rewrite_module modules/mod_rewrite.so
2、然后再在httpd.conf中书写如下规则:【绝对路径】
RewriteEngine on
//当访问任何以t_开头,以.html结尾的文件时,将$1用与(.*)匹配的字符替换后,访问相应的test.php页面
RewriteRule ^/index_(.*).html$ /index.php?id=$1
3、重启httpd
systemctl restart httpd
二、针对apache服务器下的某一目录的配置【此种配置的Rewrite规则需在此目录下建立一个.htaccess
文件来书写】
1、同上第一步
2、修改httpd.conf文件
修改httpd.conf文件中的"AllowOverride None"为"AllowOverride all",同时最好将Options
也置为"all",否则可能会出问题
3、在目录中建立.htaccess文件 【相对路径】
RewriteEngine on
RewriteRule ^index_(.*).html$ index.php?id=$1
测试篇::
cd /var/www/html
vim index.php 在此文件中 <?php var_dump($_GET['id']); ?>
访问地址为:IP/index.php?id=123 结果为:string(3) "123"
修改地址为:IP/index_123123123.html 结果为:string(6)"123123123"
设置成功!!!
windows下伪静态实现::
Apache下的Rewrite配置主要有2种::
一、针对整个apache服务器的配置
1、windows下Apache\conf\httpd.conf文件中 #LoadModule rewrite_module modules/mod_rewrite.so"前面的"#"号 去掉
2、在vhost.conf或者httpd.conf下书写:
RewriteEngine on
RewriteRule ^/t_(.*).html$/test.php?id=$1 #绝对路径 根据自己路径书写
3、重启服务
二、是针对apache服务器下的某一目录配置,此种配置需在此目录下简历一个 .hraccess
1、修改 httpd.conf 文件中的 “AllowOverride None” 为 “AllowOverride all”,同时最好将Options也设置为“all”,防止报错。
2、在运行文件同级建 .htaccess 文件【注意没有后缀】,在此文件中编写规则
RewriteEngine on
RewriteRule ^personal_(.*).html$ personalInfo.php?id=$1 //相对路径
3、在需要做伪静态页面跳转 模拟跳转路径
<a href="personal_<?php echo $v_stu['c_id']?>.html">