Nginx下设置伪静态方法与Apache差不多,直接在nginx.conf (或者在对应的*.conf) 中找到需设置伪静态规则的服务器对应字段,在server{ location/{ } }中添加以下代码:
server {
listen 80 default_server;
server_name _;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
rewrite ^(.*)list-([0-9]+)-([0-9]+)\.html$ $1list.php?page=$2&id=$3;
}
}
添加后重启Nginx服务即可生效
apache
要使用httpd.conf文件来设置伪静态策略,我们可以直接在httpd.conf中写入如下代码,如果您的网站是配置在VirtualHost中,则将这段代码加到对应的
标签内:
#输入: list-123-456.html
#输出: list.php?page=123&id=456
RewriteEngine on
RewriteRule ^(.*)list-([0-9]+)-([0-9]+)\.html$ $1list.php?page=$1&id=$2
添加完成后重启httpd服务后即可生效