Alister West

home is where your code is ...

Apache Rewrite / ProxyPass

Rewrites for glinks

RewriteEngine On
RewriteBase /
RewriteRule ^$            /cgi-bin/page.cgi [L]
RewriteRule ^index.html$  /cgi-bin/page.cgi [L]
RewriteRule ^admin/?      /cgi-bin/secure/admin.cgi [L]
RewriteRule /g/(.+)   /cgi-bin/glinks/page.cgi?g=$1 [QSA,L]
RewriteRule /p/(.+)   /cgi-bin/glinks/page.cgi?p=$1 [QSA,L]

Apache ProxyPass no-cache of backend response

By default apache caches bad backend proxy statuses (to top overloading damaged servers I suppose). During dev I never want this - so we turn it off.

# Dont cache failed response from proxied request!
# http://httpd.apache.org/docs/2.2/mod/mod_proxy.html
proxypass        / http://localhost:8012/ retry=0
proxypassreverse / http://localhost:8012/


# Proxy internally to https server (http -> https)
# a2enmod proxy_http proxy ssl
SSLProxyEngine  On
RewriteRule     ^/ajax/(.*) https://example.com/ajax/$1 [P,L]
ProxyPassReverse /ajax/     https://example.com/ajax/

Apache rewrite http -> https

# Rewrite
#  - http://domain.com     -> https://www.domain.com
#  - http://www.domain.com -> https://www.domain.com
RewriteEngine On
RewriteCond  %{HTTPS}  off  [OR]
RewriteCond  %{HTTP_HOST}  ^example.com  [NC]
RewriteRule  ^(.*)$  https://www.example.com$1  [R=301,L]

Rewrite only if file doesn't exist

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$          /cgi-bin/page.cgi?g=$1 [L]

Rewrite an image path

# moved from a flat site layout into a more structured one.
# links to files where relative and I moved all images into a
# statically served dir.

# /my-face/is_good/smiley.jpg => /images/smiley.jpg
RewriteCond %{REQUEST_URI}      !^/images
RewriteRule ^.*/([\w-]+\.jpg)$  /images/$1 [L]

Query String Rewrite

# /?area=foo => /search/query:foo
RewriteCond %{QUERY_STRING} ^area=(\w+)$
RewriteRule ^/?$  /search/query:%1    [R=301,L]
By Alister West