1

I've created a folder api/ in my www/html folder.. I've put a .htaccess file in there that looks like this

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule api/(.*)$ api/api.php?request=$1 [QSA,NC,L]
</IfModule>

In the api/ folder I have the api.php file with this code for testing;

<?php

echo $_REQUEST['request'];

?>

If I go to myserver/api/test I get a 404 not found.. So in this case I would thing it should echo test?

I've also tried putting the file in the www/html file instead of inside the api folder since I specify the api folder in the .htaccess file..

TLoe
  • 111
  • 1
  • 10
  • 1
    Sure you got mod_rewrite enabled in the first place? Remove the ifmodule check, and see if you get any errors. – CBroe Oct 25 '17 at 11:24
  • Still getting the same 404.. should the file be under api/ or in the base folder? – TLoe Oct 25 '17 at 11:27
  • If I try to go to myserver/api/api.php directly I get a 500 error – TLoe Oct 25 '17 at 11:28
  • Then check the relevant log files to find out why ... – CBroe Oct 25 '17 at 11:33
  • I actually had some failing php in the php file I had there.. I striped it out to have just what I posted above.. and I can go to myserver/api/api.php now.. but still I cannot do myserver/api/test to get it to output "test".. I have the .htaccess file in base folder.. – TLoe Oct 25 '17 at 11:50
  • php_info() says mod_rewrite is enabled – TLoe Oct 25 '17 at 12:50
  • Possible duplicate of [URL rewriting with PHP](https://stackoverflow.com/questions/16388959/url-rewriting-with-php) – codeBloger Oct 25 '17 at 13:25

1 Answers1

1

I had to set AllowOverride All in my apache2.conf file

Reference this answer:
https://stackoverflow.com/a/15662459/7417114

MrWhite
  • 43,179
  • 8
  • 60
  • 84
TLoe
  • 111
  • 1
  • 10