日期:2014-05-17  浏览次数:20453 次

ThinkPHP在SAE下关于url重写的问题
thinkphp。
根目录下有config.yaml(因为SAE不支持.htaccess)
内容为:

name: thinktest
version: 1
handle:
  - rewrite: if(!is_dir() && !is_file() && path~"^(.*)$") goto "/index.php/$1"
  - rewrite: if(path~"^/test\.html$") goto "/test.php"

关键看第二个重写。
在根目录下有test.html和test.php
访问test.html的时候可以访问到test.php

问题是
有入口文件index.php
Action里有文件IndexAction.class.php
其中index操作代码如下:

  echo "<script language='javascript'>";
  echo " location='".APP_PATH."Tpl/default/Index/test.html';";
  echo "</script>";

即页面跳转。
同时在Tpl/default/Index/下有test.html和test.php
此时跳转后不会访问到test.php

不过如果是跳转到根目录下的test.html的话就没问题。

是不是跟config.yaml的作用范围有关?还是有其他原因?

求高手解答!

------解决方案--------------------
thinkphp 的伪静态是通过 PATH_INFO 实现的
唯一可能需要使用 url 重写的是: 隐藏 index.php 文件名

thinkphp 是单一入口的,所以不会出现 http://serverName/test.php 这样的 url

这一点无论是从
.htaccess 的
RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
还是config.yaml的
- rewrite: if(!is_dir() && !is_file() && path~"^(.*)$") goto "index.php/$1"
都可以看出:他将域名外的所有内容都转换成了index.php的参数