forked from straup/flamework-api
-
Notifications
You must be signed in to change notification settings - Fork 2
/
.htaccess
63 lines (49 loc) · 3.19 KB
/
.htaccess
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# See all this stuff that's been commented out? It's a lot of hoop-jumping
# to separate API calls (api.example.com/rest) from all the other user-level
# administrative pages (example.com/api/methods) and to make sure things that
# need to be done over SSL are (like OAuth2). By default it's all commented out
# because what do I know about your webserver is configured. So spend a
# couple minutes looking at all this stuff and thinking about it and adjusting
# accordingly. Also: remember all the security around OAuth2 is predicated
# around the use of SSL. (20121103/straup)
# The API (as in both api.example.com and example.com/api)
# Ensure that all traffic to the API proper is over HTTPS
# Note that this is a api.example.com host not example.com
# (20121025/straup)
# RewriteCond %{HTTP_HOST} ^api.(.*)$
# RewriteCond %{HTTPS} off
# RewriteRule (.*) https://%{HTTP_HOST}/$1?%{QUERY_STRING} [R,L]
# The most basic rewrite, as this is the actual API
# RewriteCond %{HTTP_HOST} ^api.(.*)$
# RewriteRule ^rest/?$ api_rest.php?%{QUERY_STRING} [L]
# This one says: If we're the API and we're not hanging off /rest
# redirect to the site itself – note the %1% for capturing the domain
# sans 'api.' (20121025/straup)
# RewriteCond %{REQUEST_URI} !rest(.*)
# RewriteCond %{HTTP_HOST} ^api.(.*)$ [NC]
# RewriteRule .? http://%1%{REQUEST_URI} [R,L]
# RewriteCond %{HTTP_HOST} !^api.(.*)$
# RewriteRule ^api/rest/(.*)/?$ https://api.%{HTTP_HOST}/rest/?method=$1&%{QUERY_STRING} [R,L]
# RewriteCond %{HTTP_HOST} !^api.(.*)$
# RewriteRule ^rest/(.*)/?$ https://api.%{HTTP_HOST}/rest/?method=$1&%{QUERY_STRING} [R,L]
# The rest of the user/admin interfaces for doing API stuff
# This all (especially the oauth2 auth/token stuff) relies on the
# HTTPS rules for logged in users (20121024/straup)
RewriteRule ^api/?$ api.php [L]
RewriteRule ^api/methods/?$ api_methods.php [L]
RewriteRule ^api/methods/print/?$ api_methods.php?print=1 [L]
RewriteRule ^api/methods/explore/?$ api_methods.php [L]
RewriteRule ^api/methods/(.*)/explore/?$ api_method_explore.php?method=$1&%{QUERY_STRING} [L]
RewriteRule ^api/methods/(.*)/?$ api_method.php?method=$1&%{QUERY_STRING} [L]
RewriteRule ^api/keys/?$ api_keys.php?%{QUERY_STRING} [L]
RewriteRule ^api/keys/register/?$ api_keys_register.php?%{QUERY_STRING} [L]
RewriteRule ^api/keys/([a-zA-Z0-9]+)/?$ api_key.php?api_key=$1&%{QUERY_STRING} [L]
RewriteRule ^api/keys/([a-zA-Z0-9]+)/tokens(/page([0-9]+))?/?$ api_key_tokens.php?api_key=$1&page=$3&%{QUERY_STRING} [L]
RewriteRule ^api/oauth2/?$ api_oauth2.php?%{QUERY_STRING} [L]
RewriteRule ^api/oauth2/howto/?$ api_oauth2_howto.php?%{QUERY_STRING} [L]
RewriteRule ^api/oauth2/authenticate/?$ api_oauth2_authenticate.php?%{QUERY_STRING} [L]
RewriteRule ^api/oauth2/authenticate/like-magic/?$ api_oauth2_authenticate_like_magic.php?%{QUERY_STRING} [L]
RewriteRule ^api/oauth2/access_token/?$ api_oauth2_access_token.php?%{QUERY_STRING} [L]
RewriteRule ^api/oauth2/tokens(/page([0-9]+))?/?$ api_oauth2_tokens.php?page=$2&%{QUERY_STRING} [L]
RewriteRule ^api/oauth2/tokens/([a-zA-Z0-9]+)/?$ api_oauth2_token.php?api_key=$1&%{QUERY_STRING} [L]
RewriteRule ^rest/?$ api_rest.php?%{QUERY_STRING} [L]