Skip to content

Instantly share code, notes, and snippets.

@pnorman
Last active December 22, 2015 15:29
Show Gist options
  • Save pnorman/6492522 to your computer and use it in GitHub Desktop.
Save pnorman/6492522 to your computer and use it in GitHub Desktop.
An Apache config to handle some requests with cgimap and send others to the main API server
# Adjust as needed for the DocumentRoot. You will need to create the api
# directory, but nothing need be in it
<Directory /var/www/api>
# This section could be placed in a .htaccess file in /var/www/api, but
# the ProxyPreserveHost directive can't. If you don't have access to the
# apache config you won't be able to get OAuth to work
# Enable rewrites
RewriteEngine on
# Rewrite calls which there is only a GET version and all request methods
# can go to cgimap
RewriteRule ^0\.6/map$ - [L,H=fcgi:127.0.0.1:8000]
RewriteRule ^0\.6/(nodes|ways|relations)$ - [L,H=fcgi:127.0.0.1:8000]
RewriteRule ^0\.6/(way|relation)/([^/]+)/full$ - [L,H=fcgi:127.0.0.1:8000]
# Calls where we only want to direct the GET version to cgimap, not all
# versions. Also note that this won't capture node/#/history which aren't
# handled by cgimap
RewriteCond %{REQUEST_METHOD} ^(GET|HEAD)$
RewriteRule ^0\.6/(node|way|relation)/([^/]+)$ - [L,H=fcgi:127.0.0.1:8000]
# Fall-through to the main API server running the rails port to take calls
# not handled by cgimap
RewriteRule ^(.*) http://api.openstreetmap.org/api/$1 [P]
</Directory>
# Required for OAuth to work. The Host header is used to generate the OAuth
# signature so we can't modify it.
# This relies on api.openstreetmap.org accepting requests with a Host header
# that doesn't match a domain actually pointed to it.
ProxyPreserveHost On
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment