1.删除地址栏中index.php, 环境简介:thinkphp框架 linux(centos)php-fpm nginx
2..在thinkphp项目目录的配置文件中添加一下面代码:
'URL_CASE_INSENSITIVE'=>true,//url不区分大小写
'URL_MODEL'=>'2', //url模式
'URL_CASE_INSENSITIVE'=>false, //url可以也写成:http://localhost/thinkphp4/index.php/UserGroup/index
'URL_HTML_SUFFIX'=>'html|shtml|xml', //限制伪静态的后缀
'URL_ROUTER_ON'=>ture//开启路由
'URL_ROUTE_RULES'=>array( 'my'=>'Index/index',//静态地址路由 'my'=>'/Index/index',//静态地址路由,加/直接跳到网站根目录下。 ':id/:num'=>'Index/index',//动态地址路由,可以$_GET接收地址栏参数 'year/:year/:month/:date'=>'Index/index',//动态和静态混合地址路由 'year/:year\d/:month\d/:date\d'=>'Index/index',//动态和静态混合地址路由加上 \d代表类型只能是数字 'my/:id$'=>'Index/index',// 加上$说明地址中只能是 my/1000 后面不能有其他内容了 )
//简化 'URL_ROUTE_RULES'=>array( 'my/:year/:month:/:day'=>'Index/day', 'my/:id\d'=>'Index/index', 'my/:name'=>'Index/index', )
3.再nginx配置文件中添加下面代码
#设置重定向 location / { # rewrite ^(.*)$ index.php/$1; # index index.html index.htm index.shtml index.php; #autoindex off; if (!-e $request_filename) { rewrite ^(.*)$ /index.php?s=$1 last; break; } } location ~ \.php$ { root /home/project/test; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; send_timeout 60; fastcgi_connect_timeout 300; fastcgi_send_timeout 300; fastcgi_read_timeout 300; client_max_body_size 30m; include fastcgi_params; }