ThinkPHP在SAE下關於url重寫的有關問題
來源:互聯網
上載者:User
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 "";
即頁面跳轉。
同時在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的參數