Skip to content

Instantly share code, notes, and snippets.

@geminorum
Created June 9, 2016 00:48
Show Gist options
  • Save geminorum/7a35ed5297ae3f88c99d27c011604436 to your computer and use it in GitHub Desktop.
Save geminorum/7a35ed5297ae3f88c99d27c011604436 to your computer and use it in GitHub Desktop.
Apache “rewrite rule” for REST API

Here’s how you can configure your Apache webserver for a REST API, without using rewrite rules (thus: you don’t need the rewrite engine). Simply add the following line to your <VirtualHost>:

AliasMatch ^/api/rest/v1/(.*)$ /var/www/[mywebsite]/htdocs/api/rest/v1/index.php

In index.php, you can read the parameters like so:

$path = preg_replace('~^/rest/v1/~', '', $_SERVER['SCRIPT_NAME']);
$parts = explode('/', $path);
var_dump($parts);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment