# pass the default character set
AddDefaultCharset utf-8
# Prevent .htaccess files from being spidered or viewed via a web browser.
<FilesMatch "^\.ht">
  Order allow,deny
  Deny from all
  satisfy all
</FilesMatch>

# BAN USER BY IP
<Limit GET POST>
 order allow,deny
 allow from all
 deny from 64.233.160.0
 deny from 66.102.0.0
 deny from 66.249.64.0
 deny from 72.14.192.0
 deny from 74.125.0.0
 deny from 209.85.128.0
 deny from 216.239.32.0
 deny from 64.4.0.0
 deny from 65.52.0.0
 deny from 131.253.21.0
 deny from 157.54.0.0
 deny from 207.46.0.0
 deny from 207.68.128.0
 deny from 8.12.144.0
 deny from 66.196.64.0
 deny from 66.228.160.0
 deny from 67.195.0.0
 deny from 66.249.64.0
 deny from 72.14.192.0
 deny from 74.125.0.0
 deny from 209.85.128.0
 deny from 216.239.32.0
 deny from 64.4.0.0
 deny from 65.52.0.0
 deny from 131.253.21.0
 deny from 157.54.0.0
 deny from 207.46.0.0
 deny from 207.68.128.0
 deny from 8.12.144.0
 deny from 66.196.64.0
 deny from 66.228.160.0
 deny from 67.195.0.0
 deny from 68.142.192.0
 deny from 72.30.0.0
 deny from 74.6.0.0
 deny from 98.136.0.0
 deny from 202.160.176.0
 deny from 209.191.64.0
</Limit>

ErrorDocument 403 /

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

# Important part www seems to cause some issue with login
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]

# Blocking some of bots/crawlers/spiders
RewriteCond %{HTTP_USER_AGENT} ^(.*)googlebot(.*)$ [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^(.*)AdsBot-Google(.*)$ [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^(.*)msnbot(.*)$ [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^(.*)AltaVista(.*)$ [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^(.*)Slurp(.*)$ [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^(.*)facebookexternalhit(.*)$ [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^(.*)Twitterbot(.*)$ [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^(.*)Baiduspider(.*)$ [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^(.*)MetaURI(.*)$ [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^(.*)mediawords(.*)$ [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^(.*)FlipboardProxy(.*)$ [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^(.*)bingbot(.*)$ [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^(.*)alexa(.*)$ [NC]
RewriteRule .* - [R=403,L]