我正在尝试使用htaccess文件来使用我的RestApi,我的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/([A-Za-z0-9_.@]+)/?$" api2.php?rquest=users&email=$1 [QSA,NC,L]
</IfModule>
答案 0 :(得分: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/([A-Za-z0-9_.@]+)/?$" api2.php?rquest=users&email=$1 [QSA,NC,L]
</IfModule>