Skip to content

Instantly share code, notes, and snippets.

@jamlfy
Created June 4, 2015 06:18
Show Gist options
  • Save jamlfy/6daedaa58adcf4f42763 to your computer and use it in GitHub Desktop.
Save jamlfy/6daedaa58adcf4f42763 to your computer and use it in GitHub Desktop.
.htaccess
RewriteEngine On
# If requested resource exists as a file or directory
# (REQUEST_FILENAME is only relative in virtualhost context, so not usable)
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
# Go to it as is
RewriteRule ^ - [L]
# If non existent
# If path ends with / and is not just a single /, redirect to without the trailing /
RewriteCond %{REQUEST_URI} ^.*/$
RewriteCond %{REQUEST_URI} !^/$
RewriteRule ^(.*)/$ $1 [R,QSA,L]
# Handle CacheWatch
RewriteCond %{HTTP_USER_AGENT} baiduspider|facebookexternalhit|twitterbot|rogerbot|linkedinbot|embedly|quora\ link\ preview|showyoubot|outbrain|pinterest [NC,OR]
RewriteCond %{QUERY_STRING} _escaped_fragment_
# Proxy the request
RewriteRule ^(.*)$ http://service.cache.watch/?&access_token=<MY_TOKEN>&host=%{HTTP_HOST}&pathname=%{REQUEST_URI}&search=%{QUERY_STRING}&href=$2 [P,L]
# If non existent
# Accept everything on index.html
RewriteRule ^ /index.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment