比如有些網站的個人用戶中心注冊完后,可以自定義 **根域名后的url**. 這種需求我們描述為:
實現 http://www.xxx.com/xxx 指定到某個控制器下的方法,并獲取xxx作為參數值,來調用相關數據;
tp5我們可以這么設置:
route.php 文件:
~~~
return [
't' => 'admin/index/demo'
];
~~~
.htaccess 文件:
~~~
<IfModule mod_rewrite.c>
Options +FollowSymlinks -Multiviews
RewriteEngine On
RewriteRule ^([^/]+)$ t?id=$1
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
</IfModule>
~~~
調用 /admin/index.php 文件
~~~
public function demo()
{
echo input('get.id'); //return t
}
~~~
然后我們可以訪問:www.xxx.com/t 可以看到返回了
~~~
t
~~~