一种PHP的nginx伪静态写法

众所周知,thinkphp5的Nginx写法是这样子的:

location / {
   if (!-e $request_filename) {
      rewrite  ^(.*)$  /index.php?s=/$1  last;
   }
}

现在网站根目录下面有一个admin.php文件

请求http://abc.com/admin.php/login时候,请求会被nginx转发到index.php

按照开发需求,则需要转发至admin.php

nginx单host完整配置代码如下

server {
     listen 80;
     server_name abc.com;
     root /xxxx/xxxx;
     index index.html index.htm index.php;
     charset utf-8;
	location ~ [^/]\.php(/|$)
	{
		try_files $uri =404;
		fastcgi_pass  127.0.0.1:9000;
		fastcgi_index index.php;
		include fastcgi.conf;
		set $real_script_name $fastcgi_script_name;
		if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") {
			set $real_script_name $1;
			set $path_info $2;
		}
		fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;
		fastcgi_param SCRIPT_NAME $real_script_name;
		fastcgi_param PATH_INFO $path_info;
	}

	location / {
		if (!-e $request_filename) {
			rewrite  ^/(.*)$  /index.php?s=/$1 last;
			break;
		}
	}
}

发表评论

电子邮件地址不会被公开。 必填项已用*标注