I need to remove part of a url.
http://whatever.net/api/users/1
I want to redirect this request without api
in path to a file located in the same directory named api.php
I have following directory structure
root/api/{here we are}
So I need that my api.php
file only receives user/1
in this case
I have tried the following configuration, but it doesn't work - Not Found
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^api/(.*)$ api.php/$1 [L]
</IfModule>
Please help to get this working
Using .htaccess
Pass the modified path as a get variable
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^api/(.*)$ api.php?path=$1 [L]
</IfModule>
Using PHP
In api.php, strip the first four characters (i,e /api ) from the REQEST_URI before using it.
$required_value = substr(REQUEST_URI,5);