2014-03-01 78 views
6

我想寫htaccess的一些簡單的路由爲PHP的.htaccess路由PHP

我的文件看起來像這樣現在:

RewriteEngine On 
RewriteBase /webservices/ 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ server.php [QSA,L] 

但不起任何作用。

,我想htaccess的事情是,所有server.php呼叫都陷入這樣的:

http://localhost:8888/webservices/server.php?username=test&password=test 

寫入

http://localhost:8888/webservices/server/u/test/p/test/ 

有人能幫助我嗎?

回答

5

它實際上正在工作,因爲它將所有查詢重定向到server.php。因此

http://localhost:8888/webservices/server/u/test/p/test/ 

可以通過server.php,在這裏可以在$_SERVER["REQUEST_URI"]陣列上使用explode()容易捕捉URI的部分進行處理。忘記

http://localhost:8888/webservices/server.php?username=test&password=test 

URL結構,你將不再需要它,因爲用你剛剛寫的.htaccess,可以動態地處理每一個請求到服務器上server.php

[QSA]在你的.htaccess附加查詢字符串到URI,這是不需要的,因爲我們想擺脫它,對吧?既然你不使用這種格式,你可以刪除QSA標誌。