通俗地说,伪静态是一种可以把文件后缀改成任何可能的一种方法,比如把php或aspx动态网页文件“伪装”成静态html文件,下面来介绍几种常用的Web服务器中伪静态的配置方法。
在站点配置文件web.config中加入代码,如图1所示。
这样重启动IIS后,当
图1 在站点配置相应文件代码
在地址栏中输入:http://xxx/123-4567.html时, 实际会访问到:http://xxx/default.aspx?id1=123&id2=4 567。
首先修改一下apache目录下的httpd.conf文 件,用文本编辑器打开httpd.conf,查找以下内容:
#L o a d M o d u l e rewrite_module modules/mod_rewrite.so
把这一行最前边的#(注释)去掉即可。
然后打开站点配置文件vhosts.conf,按图2的内容进行配置。
用http://xxx/qhdedu-20181205.html这个地址访问时,实际会打开:
h t t p://x x x/i n d e x.php?id1=qhdedu&id2=20181205。
在Linux系 统中,apache的伪静态设置除了按Window s系统中的方法进行设置外,还可以利用.htaccess文件。
在apache的配置文件vhosts.conf中应该有如图3的配置。
然后在站点目录中建立.htaccess 文件(Windows中是不允许有这样的文件名的)。
在.htaccess文件中输入内容,如图4所示。
图2 在站点配置相应文件代码
图3 在站点配置相应文件代码
图4 在站点建立相应文件代码
Jexus的配置相对来讲比较简单,只需在对应的站点配置文件如re.qhdedu.com中写入:
rewrite=([a-z]{1,})-([0-9]{1,}).html$ index.php?id1=$1&id2=$2
Nginx的配置如apache一样,也有两种方法。
如re.qhdedu.com.conf 中加入以下配置:location /{
rewrite ^/([0-9]+)-([0-9]+).h t m l$ /i n d e x.php?&id1=$1&id2=$2;}
在配置文件re.qhdedu.com.conf中 写 入 :include /h o m e/w w w r o o t/re.qhdedu.com/.htaccess#引入站点根目录中.htaccess文件。
再建立.htaccess文件:# .htaccess
# nginx rewrite rule
rewrite^/([0-9]+)-([0-9]+).html$/index.php?&id1=$1&id2=$2;#end nginx rewrite rule