1

my .htaccess looks like

RewriteEngine On
RewriteRule ^api/([^/]*)$ /api.php?method=$1 [L,QSA]

my api.php looks like

class API {

    public function __construct()
    {
        require_once('helpers.php');
    }

    public function test()
    {
        dd('hey');
    }

};

$api = new API;
$method = isset( $_GET['method'] ) ? $_GET['method'] : null;

dd($_REQUEST, $_GET);

if( $method && method_exists($api, $method) ){
    $api->{$method}();
}
else {
    exit("Nothing to see here governor.");
}

Yet when i visit the rewritten url e.g. site.com/api/test i see

array (size=0)
  empty

if i change it to /api.php?method=test or /api/test?method=test i get

array (size=1)
  'method' => string 'test' (length=4)

Why is the query string not able to be detected?

The server setup is apache 2.2, php-fmt 5.6

Thanks

0

1 Answer 1

1

Since URI starting api is same PHP handler api.php I suspect it is problem of MultiViews.

Turn it off using this line at the start of your .htaccess:

Options -MultiViews

MultiViews option is used by Apache's content negotiation module that runs before mod_rewrite and makes Apache server match extensions of files. So /api can be in URL but it will serve /api.php.

Sign up to request clarification or add additional context in comments.

1 Comment

To confirm, this did fix my issue!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.