$HTTP["host"] == "www.server110.com" {
server.document-root = "/path/to/www.server110.com/"
url.rewrite = (
"^/static/.*$" => "$0",
"^/(.*)$" => "index.php/$1"
)
fastcgi.server = ( ".php" =>
( "weibo"=>( "host" => "127.0.0.1","port" => 9000) )
)
}
在apache和lighttpd里面,判断 /index.php/sth 时,如果 /index.php是一个文件,就不会当做是文件路径了
我们可以这样简单的把某些路径rewrite,达到一样的效果:
1 保持地址格式是 /index.php/control/model
2 不产生404错误或者是no input的情况
server {
index index.php index.htm;
server_name www.server110.com;
root /Data/webapps/www.server110.com; location /book/ {
if (!-e $request_filename) {
rewrite ^/book/(.*)$ /book/index.php/$1 last;
}
}
location /book/index.php {
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME /Data/webapps/www.server110.com/book/index.php;
}
}
我们还需要避免类似以下地址异常:
/book/?test 404 查询字符会查找test的control
/book/&test 错误 The URI you submitted has disallowed characters.
总体而言,是查询字符的问题,我们可以有两种方式处理:
方式一:在codeIgniter处理之前避免
我们定义系统使用REQUEST_URI来处理mvc参数,不修改系统的文件,我们修改自定义的文件
文件 application/config/config.php
指定为REQUEST_URI方式处理,不是用auto,auto方式会判断查询字符
| 'AUTO' Default - auto detects
| 'PATH_INFO' Uses the PATH_INFO
| 'QUERY_STRING' Uses the QUERY_STRING
| 'REQUEST_URI' Uses the REQUEST_URI
| 'ORIG_PATH_INFO' Uses the ORIG_PATH_INFO
|
*/
$config['uri_protocol'] = "REQUEST_URI";
文件 index.php
我们可以直接砍掉查询字符,保证参数不受影响
//处理查询字符
$url = explode('?', $_SERVER['REQUEST_URI']);
$url = explode('&', $url[0]);
$_SERVER['REQUEST_URI'] = $url[0]; /*
|---------------------------------------------------------------
| LOAD THE FRONT CONTROLLER
|---------------------------------------------------------------
|
| And away we go...
|
*/
require_once BASEPATH.'codeigniter/CodeIgniter'.EXT;
方式二:发生错误之后调整
发生404错误时,我们自动跳转到相应的地址,比如去掉后面 ?xxxx 和 &xxxx
文件 application/errors/error_404.php
<?php
$url = explode('?', $_SERVER['REQUEST_URI']);
$url = explode('&', $url[0]);
if($url[0] != $_SERVER['REQUEST_URI']){
echo "<meta http-equiv="refresh" content="0;url=$url[0]">";
}
?>
</head>
在 error_general.php 里也可以这样加一样的代码。