來源:http://www.thinkphp.cn/topic/26637.html
環境:nginx 1.6,thinkphp3.2.2
第一步,修改server塊
server { listen 80; server_name www.domain.com domain.com; error_page 404 /404.html; error_page 500 502 503 504 /50x.html; #這個location塊處理動態資源請求. location ~ \.php { root /data0/htdocs/www; fastcgi_pass 127.0.0.1:9000; include fastcgi.conf; } #這個location處理能處理所有的靜態資源 location / { root /data0/htdocs/www; index index.php index.html index.htm; #如果請求資源既不是靜態目錄資源(目錄資源就是請求該目錄下的默認首頁index指令指定的默認資源), #也不是靜態文件資源時候,就需要腳本動態生成,重寫后重新用第一個處理動態請求的location塊處理。 if (!-e $request_filename){ #一定要用(.*)匹配整個URI,包含URI第一個字符反斜杠/ rewrite ^(.*)$ /index.php?s=$1 last; } } }
第二步:打開thinkphp框架的配置文件convention.php,
修改URL_MODEL=>3,采用rewrite兼容模式,並且修改
'VAR_PATHINFO'=> 's', 重寫時我們用的是s=""的形式.
第三步:在瀏覽器輸入:www.domain.com,結果如下:
:)
歡迎使用 ThinkPHP!
[ 您現在訪問的是Home模塊的Index控制器 ]
第四步:在瀏覽器中輸入URL時候,還是用rewrite形式的url,就是不要輸入入口文件了,其它的不變,例如:
http://www.domain.com/module/controler/action/參數1/值1/參數2/值2/
網址中不再需要輸入入口文件index.php了,因為在剛才重寫時我們已經指定好了入口文件index.php。
注意不推薦用rewrite兼容模式,推薦用rewrite模式:
http://www.thinkphp.cn/topic/26657.html