正则表达式如何写呢?

rewrite ^/news-catid-([0-9]+)\.html$ /news.php?catid=$1;
rewrite ^/(.*)/news-catid-([0-9]+)\.html$ /$1/news.php?catid=$2;
这两条伪静态能合成一条吗?
rewrite ^/(.*)/category-catid-([0-9]+)\.html$ /$1/news.php?catid=$2;
rewrite ^/(.*)/category-catid-([0-9]+)-car_brand-([0-9a-z])\.html$ /$1/news.php?catid=$2&car_brand=$3;
这两条伪静态能合成一条吗?

第1个回答  2019-05-27
rewrite ^/news-catid-([0-9]+)\.html$ /news.php?catid=$1;
rewrite ^/(.*)/news-catid-([0-9]+)\.html$ /$1/news.php?catid=$2;
合并为
rewrite ^/(.*)news-catid-([0-9]+)\.html$ (/$1)?/news.php?catid=($1|$2);
以下

rewrite ^/(.*)/category-catid-([0-9]+)\.html$ /$1/news.php?catid=$2;
rewrite ^/(.*)/category-catid-([0-9]+)-car_brand-([0-9a-z])\.html$ /$1/news.php?catid=$2&car_brand=$3;
合并为
rewrite ^/(.*)/category-catid-([0-9]+)(-car_brand-([0-9a-z]))?\.html$ /$1/news.php?catid=$2(&car_brand=$3)?;本回答被网友采纳