2015-11-09 74 views
0

我試圖做一個htaccess文件,我RESTAPI工作,我的htaccess位於我的.htaccess文件有什麼問題?

http://www.example.com/appregalos/ApiRest` 

我的問題是,如果我寫

http://www.example.com/appregalos/ApiRest/users` 

它沒有做任何事情,但我想要做的動作是重定向到

http://www.example.com/appregalos/ApiRest/api2.php?rquest=users 

發生了什麼事?

<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-s 
RewriteRule ^([A-Za-z]+)/?$ api2.php?rquest=$1 [QSA,NC,L] 
RewriteRule "^users/([0-9]+)/?$" api2.php?rquest=users&id=$1 [QSA,NC,L] 
RewriteRule "^users/([[email protected]]+)/?$" api2.php?rquest=users&email=$1 [QSA,NC,L] 
</IfModule> 

回答

2

如果你的.htaccess位於

http://www.example.com/appregalos/ApiRest 

您應該使用RewriteBase該目錄。

<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteBase /appregalos/ApiRest/ 
RewriteCond %{REQUEST_FILENAME} -d [OR] 
RewriteCond %{REQUEST_FILENAME} -f 
RewriteRule^- [L] 

RewriteRule ^([A-Za-z]+)/?$ api2.php?rquest=$1 [QSA,NC,L] 
RewriteRule "^users/([0-9]+)/?$" api2.php?rquest=users&id=$1 [QSA,NC,L] 
RewriteRule "^users/([[email protected]]+)/?$" api2.php?rquest=users&email=$1 [QSA,NC,L] 
</IfModule> 
+0

此解決方案是完美的!!!!!!! 這是所有的! – Kargol