Nginx 常用伪静态配置

1. /a/b?c=d => index.php?_a=a&_m=b&c=d

2. /xxx/detail-yyy.html => index.php?_a=xxx&_m=detail&id=yyy

server {
	listen       80;
	server_name  my.xh5.com;

	location / {
		root   /mnt/hgfs/web/my.xueh5.com/src/;
		index  index.html index.htm index.php;

		if ($args ~ "^(.*)$"){
			set $rule_0 1$rule_0;
			set $bref_1 $1;
		}
		if ($rule_0 = "1"){
			rewrite ^([0-9a-zA-Z]*)/detail-([0-9]*).html$ /index.php?_a=$1&_m=detail&id=$2&$bref_1 last;
			rewrite ^/([0-9a-zA-Z]*)/([0-9a-zA-Z.]*)$ /index.php?_a=$1&_m=$2&$bref_1 last;
			rewrite ^/([0-9a-zA-Z]+)$ /index.php?_a=$1&_m=index&$bref_1 last;
			rewrite ^/$ /index.php?_a=index&_m=index&$bref_1 last;
		}
	}

	location ~ .php$ {
		root           /mnt/hgfs/web/my.xueh5.com/src/;
		fastcgi_pass   127.0.0.1:9000;
		fastcgi_index  index.php;
		fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
		include        fastcgi_params;
	}
}

  

原文地址:https://www.cnblogs.com/hefei/p/5509247.html