伪静态原理
时间:
阅读:480
伪静态原理
最佳回答
伪静态实现的原理就是 index.php?act=about&cid=1 将这种形式的动态路径用 about-1.html 这种形式输出,根据不同的服务器环境,配置方法也不太一样,PHP+iis6的话就要配置httpd.ini文件,php+iis7就要配置web.config,PHP+apache就要配置.htaccess文件
.htaccess规则示例:
RewriteEngine on
RewriteRule ^/?(index|guestbook|online).html$ index.php [L]
RewriteRule ^/?(eindex).html$ index.php?act=$1 [L]
RewriteRule ^/?(index|guestbook|online)-([0-9]+).html$ index.php?p=$2 [L]
RewriteRule ^/?([a-z0-9]+)_([0-9]+).html$ index.php?act=$1&id=$2 [L]
RewriteRule ^/?([a-z0-9]+)-([0-9]+).html$ index.php?act=$1&cid=$2 [L]
RewriteRule ^/?([a-z0-9]+)-([0-9]+)-([0-9]+).html$ index.php?act=$1&cid=$2&p=$3 [L]
httpd.ini示例:
[ISAPI_Rewrite]
RepeatLimit 32
# Block external access to the httpd.ini and httpd.parse.errors files
RewriteRule /httpd(?:.ini|.parse.errors).* / [F,I,O]
# Block external access to the Helper ISAPI Extension
RewriteRule .*.isrwhlp / [F,I,O]
RewriteRule ^/(index|guestbook|online).html$ /$1.php
RewriteRule ^/(eindex).html$ /index.php?act=$1
RewriteRule ^/(index|guestbook|online)-([0-9]+).html$ /$1.php?p=$2
RewriteRule ^/([a-z0-9]+)_([0-9]+).html$ /index.php?act=$1&id=$2
RewriteRule ^/([a-z0-9]+)-([0-9]+).html$ /index.php?act=$1&cid=$2
RewriteRule ^/([a-z0-9]+)-([0-9]+)-([0-9]+).html$ /index.php?act=$1&cid=$2&p=$3
.htaccess规则示例:
RewriteEngine on
RewriteRule ^/?(index|guestbook|online).html$ index.php [L]
RewriteRule ^/?(eindex).html$ index.php?act=$1 [L]
RewriteRule ^/?(index|guestbook|online)-([0-9]+).html$ index.php?p=$2 [L]
RewriteRule ^/?([a-z0-9]+)_([0-9]+).html$ index.php?act=$1&id=$2 [L]
RewriteRule ^/?([a-z0-9]+)-([0-9]+).html$ index.php?act=$1&cid=$2 [L]
RewriteRule ^/?([a-z0-9]+)-([0-9]+)-([0-9]+).html$ index.php?act=$1&cid=$2&p=$3 [L]
httpd.ini示例:
[ISAPI_Rewrite]
RepeatLimit 32
# Block external access to the httpd.ini and httpd.parse.errors files
RewriteRule /httpd(?:.ini|.parse.errors).* / [F,I,O]
# Block external access to the Helper ISAPI Extension
RewriteRule .*.isrwhlp / [F,I,O]
RewriteRule ^/(index|guestbook|online).html$ /$1.php
RewriteRule ^/(eindex).html$ /index.php?act=$1
RewriteRule ^/(index|guestbook|online)-([0-9]+).html$ /$1.php?p=$2
RewriteRule ^/([a-z0-9]+)_([0-9]+).html$ /index.php?act=$1&id=$2
RewriteRule ^/([a-z0-9]+)-([0-9]+).html$ /index.php?act=$1&cid=$2
RewriteRule ^/([a-z0-9]+)-([0-9]+)-([0-9]+).html$ /index.php?act=$1&cid=$2&p=$3
最新回答共有2条回答
-
游客
回复如果你的网站服务器支持ISAPI_Rewrite,用httpd.ini放置在根目录下,httpd.ini内容如下:
[ISAPI_Rewrite]
# 3600 = 1 hour
CacheClockRate 3600
RewriteRule /index.html /index.php
这样访问index.html就先当于是在访问index.php
RewriteRule /index_id-(.+).html$ /index.php?id=$1
如:index.php?id=2
用index_id-2.html就相当于是在访问index.php?id=2
如果是apache服务品,规则是放置在.htaccess里面的,语法稍有不同,原理是差不多的!
来个匿名先 - -