#第一种 普通get多参数方式
htt://www.jb100.net/index.php?m=Info&a=usrInfo
#第二种 pathinfo方式
htt://www.jb100.net/index.php/Info/usrInfo
#带有get的其他变量
htt://www.jb100.net/index.php/Info/usrInfo/Id/1
#第三种 普通get单参数方式 ThinkPHP中又称”兼容模式“#第一种
htt://www.jb100.net/index.php/Info/usrInfo.html
#第二种
htt://www.jb100.net/index.php?s=Info/usrInfo.html
======
print_r(pathinfo('http://www.jb100.net/test/index.txt'));
?>
结果:Array
(
[dirname] => http://www.jb100.net/test
[basename] => index.txt
[extension] => txt
[filename] => index
)
通过以上运行结果,可以看到打印出来的数组key字段已经很明显的标示出其意义来了。http://www.jb100.net/index.php/Usr/UsrInfo
简单点理解,上述格式化的url形式就是ThinkPHP需要支持的pathinfo路径模式。对这个种格式化的url进行稍微解释,访问这个么一个地址,对基于ThinkPHP框架的网站来说,实际需要执行的就是网站根目录下的index.php文件,而该url中后面的/Usr/UsrInfo则被作为mvc思路中的功能模块参数与控制器参数,转换为普通get方式传参则上述url就要变为:http://www.jb100.net/index.php?m=Usr&a=UsrInfo
当然,get参数的变量该例子中一个是m一个是a,这个变量名在ThinkPHP中是可以改变的,这就需要依据具体的基于ThinkPHP的应用的模块规划与喜好了。location / {
root /var/www;
index index.html index.htm index.php;
if (!-d $request_filename) {
rewrite ^/(.*)/(.*)/*$ /index.php?m=$1&a=$2 last;
break;
}
}
但问题出现了,基于ThinkPHP的应用不仅仅只有上述例子中的这种pathinfo模式,现在变成这样的了:(为了便于解说,称如下代码段为“url示例”,后方提到“url示例”就是指此处的三种url格式)http://www.jb100.net/index.php/Usr/UsrInfo.html
#第二种,隐藏脚本文件index.phphttp://www.jb100.net/Usr/UsrInfo
或
http://www.jb100.net/Usr/UsrInfo/
#第三种,需要在访客看到的网址中隐藏掉index.php,且带.html后缀http://www.jb100.net/Usr/UsrInfo.html
再了解下ThinkPHP中处理url的各种逻辑,ThinkPHP对传参进行了多种判定与处理,除了get方式传递不同的get变量作为mvc中的控制变量外,还有一个“兼容模式”的传参规则,也就是如下:http://www.jb100.net/index.php?s=/Usr/UsrInfo
这种传参形式依然是get方式传参,但省略了多个get参数。ThinkPHP框架会对获取到的get变量$_GET['s']进行处理,从其中提取出mvc所需要的各个控制变量。location / {
root /var/www;
index index.html index.htm index.php;
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=$1 last;
break;
}
}
那么,现在需要同时兼容上述url示例中的三种格式又出问题了。最后解决方法如下:location / {
root /var/www;
index index.html index.htm index.php;
if (!-e $request_filename) {
rewrite ^/index.php(.*)$ /index.php?s=$1 last;
rewrite ^(.*)$ /index.php?s=$1 last;
break;
}
}
转载原文地址:http://www.jb100.net/html/content-28-519-1.html AD:真正免费,域名+虚机+企业邮箱=0元
已抢111447个
抢已抢47272个
抢已抢133908个
抢已抢32465个
抢已抢345个
抢已抢801个
抢