-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.htaccess
More file actions
49 lines (39 loc) · 1.89 KB
/
Copy path.htaccess
File metadata and controls
49 lines (39 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# REST configuration of Apache Web Server software
# by Johan Basberg
# Valid requests format with optional query string:
# <domain>/api/v<integer>/<action>[request string]
# <domain> the domain where this file resides.
# <integer> the version number of the API.
# <action> verbs, entities, identifiers and any number of backslashes.
# [request string] is an optional request string.
# Example requests:
# http://domain.com/api/v1/users/1?session=abcd1234
# http://domain.com/api/v1/users?session=abcd1234;product=calendar
# http://domain.com/api/v1/getUsers
# --------------------------------------------------------------------
# Disabling caching in PHP
# Caching has to be disabled before the PHP script runs:
php_flag opcache.enable Off
# Enable rewriting of /api/ calls
RewriteEngine On
# Disable caching
RewriteRule .? - [ENV="Cache-Control: no-cache, must-revalidate",ENV="Pragma: no-cache"]
# Replace /api/ with the relative path to your endpoint
RewriteBase /api/
# REST Action without a Query String
# If there is a match, no additional rules will be executed.
# Rewrite rules for API Version and Action, without a query string:
# http://yourdomain.com/api/v1/requiredAction/someId ->
# http://yourdomain.com/api/index.php?api=v1&action=requiredAction/someId
RewriteCond %{QUERY_STRING} ^$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_URI} /v([0-9]+)/([a-zA-Z0-9\/]+)
RewriteRule ^v([0-9]+)/([a-zA-Z0-9\/]+)/?$ index.php?api=$1&action=$2 [last]
# REST Action with Query String
# Rewrite for API Version and Action with an additional query string:
# http://yourdomain.com/api/v1/requiredAction/someId?query=string ->
# http://yourdomain.com/api/index.php?api=v1&action=requiredAction/someId&query=string
RewriteCond %{QUERY_STRING} .
RewriteRule ^v([0-9]+)/([a-zA-Z0-9\/]+)/?$ index.php?api=$1&action=$2&%{QUERY_STRING} [last]