RewriteEngine On

# Maintenance page
#RewriteCond %{REQUEST_URI} !/offline.php
#RewriteCond %{REQUEST_URI} !/static/.*
#RewriteCond %{REQUEST_URI} !/download/.*
#RewriteRule .* /offline.php [L]

#ErrorDocument 503 /offline.php

# Block ALAN_DB requests
RewriteCond %{REQUEST_URI} ^/groups/2913367/alan_db$
RewriteCond %{HTTP_USER_AGENT} "=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.1 Safari/605.1.15" [OR]
RewriteCond %{HTTP_USER_AGENT} petalbot
RewriteCond %{HTTP_REFERER} ^$
RewriteRule ^.* - [F,L]

RewriteCond %{HTTP_REFERER} "=http://alandb.darksky.org/img/94x94xlogo.png.pagespeed.ic.nlRR4-FDvP.png"
RewriteRule ^.* - [F,L]

RewriteCond %{HTTP_USER_AGENT} AhrefsBot [OR]
RewriteCond %{HTTP_USER_AGENT} okhttp [OR]
RewriteCond %{HTTP_USER_AGENT} "^Mozilla [0-9]+\.[0-9]+\.[0-9]+$"
RewriteRule ^.* - [F,L]

# 'scrapy' bot on forums
Deny from 50.37.126.65

Deny from 146.70.45.221
Deny from 156.146.37.122
Deny from 20.190.1.177

Deny from 45.130.136.50
Deny from 45.130.136.51

Options +MultiViews

AddDefaultCharset utf-8
AddType image/x-icon .ico
AddType text/javascript .mjs

# Legacy rewrites
RewriteRule ^index.php/feed.*$ http://feeds.feedburner.com/zotero [R=301,L]
RewriteRule ^feed.*$ http://feeds.feedburner.com/zotero [R=301,L]
RewriteRule ^video(.*)$ /static/video$1 [R=301,L]
RewriteRule ^documentation($|\/.*$) /support$1 [R=301,L]
RewriteRule ^images/promote/(.*)$ /static/images/promote/$1 [L]
RewriteRule ^wp-content/themes/working/images/zotero_screenshot.jpg$ /static/images/index/zotero_screenshot.jpg [L]
RewriteRule ^wp-content/themes/working/images/zotero_screenshot_500.gif$ /static/images/legacy/zotero_screenshot_500.gif [L]
RewriteRule ^translators/?$ /support/translators [R,L]
RewriteRule ^translators-status /support/translators [R,L]
# Temp until 5.0 Final
RewriteRule ^extensions$ /download/connectors [R,L]

RedirectPermanent /trademark https://www.zotero.org/support/terms/trademark
Redirect /zoter.jpg https://www.zotero.org/static/images/about/zoter.jpg

Redirect /support/storage /storage
Redirect /support/institutional_storage /storage/institutions

Redirect /.well-known/change-password /settings/security

# Performance tweaks: gzip, far-future expires, no etags
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css application/x-javascript text/javascript application/javascript
<filesmatch "\.(gif|png|jpg|js|css|swf|pdf|flv)$">
    ExpiresActive on
    ExpiresDefault "access plus 1 day"
</filesmatch>
FileETag none

# Rewrite Rules

#Rules for Versioned Static Files
RewriteRule (static/.+)\.(\d{10})\.(\w{2,4})$ $1.$3 [L]
#special case for web-library directory since the deep urls are hard to update after building
#the path for web-library will have a timestamp added when web-library is deployed (/web-library.123456/)
RewriteRule ^static/web-library\-[\d]+/(.*)$ /static/web-library/$1 [L]

# Feed pages into Zend Framework
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{REQUEST_URI} !/download/.*
RewriteCond %{REQUEST_URI} !/images/.*
RewriteCond %{REQUEST_URI} !/include/.*
RewriteCond %{REQUEST_URI} !/utils/.*
RewriteCond %{REQUEST_URI} !^/support/.*
RewriteCond %{REQUEST_URI} !/forum/.*
RewriteCond %{REQUEST_URI} !/blog/.*
RewriteCond %{REQUEST_URI} !/static/.*
RewriteCond %{REQUEST_URI} !/selenium/.*
RewriteCond %{REQUEST_URI} !/phpdocs/.*
RewriteRule ^(.*)$ index.php/$1
