返回列表 回复 发帖

稳定版nginx的伪静态规则(吐血贡献)

本人对Apache2.2,nginx rewrite 技术不熟,发了3天研究出来的,希望对你们有些帮助。nginx伪静发其实很简单,本来是一个小时搞定的事,官方给的.htaccess文件误导了我。RewriteRule ^information-(.+)/\?*(.*)$ buy_list\.php\?limit=$1 跳转的目标中的.和?好像不需要转义吧,应该这样才对:buy_list.php?limit=$1
以下是nginx 重定向配置
打开nginx.conf配置文件 贴到server 中,我是放到结尾 ,404报错定向到404.php
server {
……
error_page  404              /404.php;
……
rewrite ^/product-(.+)-(.+)-(.+)/\?*(.*)$ /product_list.php?firstRow=$1&totalRows=$2&id=$3 last;
rewrite ^/product-(.+)-(.+)/\?*(.*)$ /product_list.php?firstRow=$1&totalRows=$2 last;
rewrite ^/product-(.+)/\?*(.*)$ /product_list.php?id=$1 last;
rewrite ^/product/\?*(.*)$ /product_list.php last;
rewrite ^/products-category/ /products_category.php last;
rewrite ^/news-(.+)/ /news_detail\.php?id=$1 last;
rewrite ^/bizserver-(.+)-(.+)-(.+)/ /news_list.php?firstRow=$1&totalRows=$2&id=$3 last;
rewrite ^/bizserver-(.+)/ /news_list.php?id=$1 last;
rewrite ^/bizserver/ /biz_server.php last;
rewrite ^/exhibition/ /exhibition.php last;
rewrite ^/exhibition-detail/(.+) /exhibition_detail.php?id=$1 last;
rewrite ^/exhibition-(.+)-(.+)/\?*(.*)$ /exhibition.php?firstRow=$1&totalRows=$2 last;
rewrite ^/company-(.+)-(.+)-(.+)/\?*(.*)$ /company_list.php?firstRow=$1&totalRows=$2&id=$3 last;
rewrite ^/company-(.+)-(.+)/\?*(.*)$ /company_list.php?firstRow=$1&totalRows=$2 last;
rewrite ^/company-(.+)/\?*(.*)$ /company_list.php?id=$1 last;
rewrite ^/company/\?*(.*)$ /company_list.php last;
rewrite ^/companys-category/\?*(.*)$ /companys_category.php last;
rewrite ^/uhome-(.+)-(.+)-(.+)-(.+) /shop.php?firstRow=$3&totalRows=$4&uid=$2&action=$1 last;
rewrite ^/uhome-(.+)-(.+)-(.+) /shop.php?uid=$2&action=$1&id=$3 last;
rewrite ^/uhome-(.+)-(.+) /shop\.php?uid=$1&action=$2 last;
rewrite ^/uhome-(.+) /shop\.php?uid=$1 last;
rewrite ^/info-(.+)-(.+)-(.+)/\?*(.*)$ /buy_list.php?firstRow=$1&totalRows=$2&id=$3 last;
rewrite ^/info-(.+)-(.+)/\?*(.*)$ /buy_list.php?firstRow=$1&totalRows=$2 last;
rewrite ^/info-(.+)/\?*(.*)$ /buy_list.php?id=$1 last;
rewrite ^/info/\?*(.*)$ /buy_list.php last;
rewrite ^/information-(.+)/\?*(.*)$ /buy_list.php?limit=$1 last;
rewrite ^/buy-category/\?*(.*)$ /buy_category.php last;
rewrite ^/job/ /job.php last;
rewrite ^/announcement/(.+) /announcement.php?id=$1 last;
rewrite ^/changelink/ /change_link.php  last;
}

朋友的公司想做个b2b电子商务,百度,google 搜了搜,php中友邻、php168 b2b、B2Bbuilder都试用一下,B2Bbuilder,在UC整合,多语言相对好一些,标签跨站调用,纯净发技术功能不足,希望官方多下点功夫。等着买你们的授权呢。
1

评分次数

给你顶起来!加了18分,精华帖哦
淡然而遇,随意而行。深深浅浅的思念在心。宠辱不惊,闭看门前花开花落;去留无意,漫随天外云卷云舒!
很不错
本帖最后由 ramboo 于 2009-10-21 22:50 编辑

rewrite ^/uhome-(.+)-(.+) /shop\.php?uid=$1&action=$2 last;
rewrite ^/uhome-(.+) /shop\.php?uid=$1 last;

这两条规则有误,应该去掉后面的转移斜杠。另外就是这样写不是很严谨。我修改了一下:
rewrite ^/uhome-(\w+)-([0-9]+)-(.+) /shop.php?uid=$2&action=$1&id=$3 last;
rewrite ^/uhome-([0-9]+)-(\w+) /shop.php?uid=$1&action=$2 last;

完整的规则,请看我的博客:

http://www.iamramboo.com/?p=3
不错
顶  希望我们的 B2BBUILDER 越来越好
玩的就是心跳-秀的就是激情
不错,支持一下。
中国窗帘网现在建设中.......
窗帘论坛
返回列表