# 1. 隱藏index.php
在入口文件的同級添加.htaccess文件,雖然官方自帶了此文件,但在phpstudy環境下不起作用。
修改其內容為:
~~~
<IfModule mod_rewrite.c>
Options +FollowSymlinks -Multiviews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [L,E=PATH_INFO:$1]
</IfModule>
~~~
接下來就可以使用下面的URL地址訪問了
~~~
http://tp5.com/index/index/index
http://tp5.com/index/index/hello
~~~
> 上述URL隱藏了`index.php`。
# 2. 定義路由
定義了路由,但結果不對,那最低級的錯誤就是沒有**一個字一個字的讀教程**,路由定義文件(application/route.php),在application目錄下啊。
# 3. 錯誤的URL
`http://tp5.com/hello/` //最后的“/”是多余的
`http://tp5.com/hello/abcde` //這個能正確的返回hello abcde
`http://tp5.com/hello/2222` //數字開頭,不行?
`http://tp5.com/hello/漢字` //也不行,且報錯?
# 4. 設置URL分隔符
分割符可以是 / , - , --- , = , ?等等
# 5. 增加一個控制器類
~~~
<?php
namespace app\index\controller;
class Blog
{
public function get($id)
{
return '查看id=' . $id . '的內容';
}
....
}
~~~
這個類怎么加?現在還不會....