nginx、Apache重写规则

apache

ErrorDocument 404 /404.php
RewriteEngine On
RewriteBase /
RewriteCond %{http_host} ^qa8.chinajm.cn [NC]
RewriteRule ^(.*)$ http://www.qa8.chinajm.cn/$1 [L,R=301]
RewriteRule ^(.*)\.(asp|aspx|asa|asax|dll|jsp|cgi|fcgi|pl)(.*)$ /404.php
RewriteRule ^(admin|cache|file|include|lang|module|skin|template)/(.*)\.php(.*)$ /404.php
RewriteCond %{HTTP_HOST} ^www\.(qa8\.)?chinajm\.cn$
RewriteRule ^(.+/|)index\.(php|html?|shtml?)$ http://www.%1chinajm.cn/$1 [R=301,L]
#所有访问都带斜杠
RewriteRule ^([^\.\?]+?[^/])(\??|\?.*)$ $1/$2 [R=301,L]
RewriteRule ^(.*)-htm-(.*)$ $1.php?$2
RewriteRule ^(.*)/show-([0-9]+)([\-])?([0-9]+)?\.html$ $1/show.php?itemid=$2&page=$4
RewriteRule ^(.*)/list-([0-9]+)([\-])?([0-9]+)?\.html$ $1/list.php?catid=$2&page=$4
RewriteRule ^(.*)/([A-za-z0-9_\-]+)-c([0-9]+)-([0-9]+)\.html$ $1/list.php?catid=$3&catdir=$2&page=$4
RewriteRule ^(.*)/show/([0-9]+)/([0-9]+)?([/])?$ $1/show.php?itemid=$2&page=$3
RewriteRule ^(.*)/list/([0-9]+)/([0-9]+)?([/])?$ $1/list.php?catid=$2&page=$3
RewriteRule ^(.*)/([0-9]+)-([0-9]+)-([0-9]+)-([0-9]+)\.html$ $1/index.php?moduleid=$2&catid=$3&itemid=$4&page=$5
RewriteRule ^(.*)/([A-za-z]+)/(.*)\.shtml$ $1/$2/index.php?rewrite=$3
#RewriteRule ^(com)/([A-za-z0-9_\-]+)/([A-za-z]+)/(.*)\.html$ index.php?homepage=$2&file=$3&rewrite=$4
#RewriteRule ^(com)/([A-za-z0-9_\-]+)/([A-za-z]+)([/])?$ index.php?homepage=$2&file=$3
#RewriteRule ^(com)/([A-za-z0-9_\-]+)([/])?$ index.php?homepage=$2
#ajax.php => ajax.json
RewriteRule ^(.*?)ajax\.json(.*)$ $1ajax.php$2    [L,NC]
#品牌单页
RewriteRule ^(co-)([A-za-z0-9_\-]+)([/])?$ index.php?homepage=$2
RewriteRule ^(co-)([A-za-z0-9_\-]+)/(news)(?:/)(?:(\d+)(?:/))?$ index.php?homepage=$2&file=$3&page=$4
#行业站
RewriteRule ^hangye(?:/)?$  invest/hangye.php [L]
RewriteRule ^top(?:/)?$  top/index.php [L]
RewriteRule ^([A-za-z0-9_\-]+)(?:/)?$  invest/hangye.php?catdir=$1 [L]

 

nginx

#www.chinajm.cn重写文件
rewrite "^/(.*)\.(asp|aspx|asa|asax|dll|jsp|cgi|fcgi|pl)(.*)$" /404.php;
rewrite "^/(admin|cache|file|include|lang|module|skin|template)/(.*)\.php(.*)$" /404.php;

#index.php跳转到根目录
if ($request_uri ~* (.*?)/index.(html|shtml|php)) {
 return 301 $scheme://$host;
}
if (!-e $request_filename) {
    #所有访问都带斜杠
    rewrite ^/([^\.\?]+?[^/])(\??|\?.*)$ /$1/$2 permanent;
    
    #news下面规则start
    #排行榜重写;
    rewrite "^/news/top([A-za-z0-9_\-]+)/([0-9]+)?/?$" /top/list.php?catdir=$1&page=$2 last;
    #找项目重写;
    rewrite "^/news/xiangmu/(.*)-htm-(.*)$" /invest/$1.php?$2 last;
    rewrite "^/news/xiangmu/(.*)?(?:/)?$" /invest/list.php last;
    #精选品牌;
    rewrite "^/news/jxpp(?:/)?$" /top/jxpp.php last;
    #标签;
    rewrite "^/news/bq-([A-za-z0-9_\-]+)/(\d+)?/?$" /news/label.php?&action=list&letter=$1&page=$2 last;
    #新闻生成;
    rewrite "^/news/((?:\d{4})/(?:\d{4})(\d+)(?:-(\d+))?\.(?:s?)html)$" /news/show.php?itemid=$2&page=$3&htmlfile=$1 last;
    rewrite "^/news/(zsnews)/(?:(\d+)(?:/))?$" /news/list.php?catdir=$1&page=$2 last;
    #行业新闻;
    rewrite "^/news/([a-z0-9]+)/(?:(\d+)(?:/))?$" /news/hangye.php?hangyedir=$1&page=$2 last;
    rewrite "^/news/([a-z0-9]+)/([a-z]+)(?:/)(?:(\d+)(?:/))?$" /news/hangye.php?hangyedir=$1&catdir=$2&page=$3 last;
    rewrite "^/news/hangye/$" /zhaoshang/hangye.php last;
    #news下面规则end

    rewrite "^/(.*)-htm-(.*)$" /$1.php?$2;
    rewrite "^/(.*)/show-([0-9]+)([\-])?([0-9]+)?\.html$" /$1/show.php?itemid=$2&page=$4;
    rewrite "^/(.*)/list-([0-9]+)([\-])?([0-9]+)?\.html$" /$1/list.php?catid=$2&page=$4;
    rewrite "^/(.*)/([A-za-z0-9_\-]+)-c([0-9]+)-([0-9]+)\.html$" /$1/list.php?catid=$3&catdir=$2&page=$4;
    rewrite "^/(.*)/show/([0-9]+)/([0-9]+)?([/])?$" /$1/show.php?itemid=$2&page=$3;
    rewrite "^/(.*)/list/([0-9]+)/([0-9]+)?([/])?$" /$1/list.php?catid=$2&page=$3;
    rewrite "^/(.*)/([0-9]+)-([0-9]+)-([0-9]+)-([0-9]+)\.html$" /$1/index.php?moduleid=$2&catid=$3&itemid=$4&page=$5;
    rewrite "^/(.*)/([a-z]+)/(.*)\.shtml$" /$1/$2/index.php?rewrite=$3;
    #ajax.php => ajax.json;
    rewrite "^/(.*?)ajax\.json(.*)$" /$1ajax.php$2    last;
    #品牌单页;
    rewrite "^/(co-)([a-z0-9_\-]+)([/])?$" /index.php?homepage=$2;
    rewrite "^/(co-)([a-z0-9_\-]+)/(news)(?:/)(?:(\d+)(?:/))?$" /index.php?homepage=$2&file=$3&page=$4;
    #行业站;
    rewrite "^/(.*)\.(asp|aspx|asa|asax|dll|jsp|cgi|fcgi|pl)(.*)$" /404.php;
    rewrite "^/(admin|cache|file|include|lang|module|skin|template)/(.*)\.php(.*)$" /404.php;
    rewrite "^/hangye(?:/)?$"  /invest/hangye.php last;
    rewrite "^/top(?:/)?$"  /top/index.php last;
    rewrite "^/([a-z0-9_\-]+)(?:/)?$"  /invest/hangye.php?catdir=$1 last;
}

posted @ 2019-12-27 10:14  飞鹰之歌  阅读(318)  评论(0编辑  收藏  举报