title: .htaccess ERRORDOCUMENT not working
body: <p>Hope someone can help with this.</p>
  
  <p>I have the following code which checks the user agent of visitors and throws an error</p>
  
  <pre><code># ANYWHERE IN UA
  RewriteCond %{HTTP_USER_AGENT} ^.* (exabot|craftbot|download|extract|stripper|sucker|ninja|clshttp|webspider|leacher|collector|grabber|webpictures).*$ [NC]
  
  # SERVE ERRORDOCUMENT
  RewriteRule . - [F,L]
  
  ErrorDocument 500 /errorPage500.php
  </code></pre>
  
  <p>For some reason unknown to me the error document fails with the following error</p>
  
  <p>Forbidden</p>
  
  <p>You don't have permission to access / on this server.</p>
  
  <p>Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.</p>
  
  <p>Do I need to add more code for this to work?</p>
  
  <p>Thanks in advance</p>
  
  <p>Full code below</p>
  
  <pre><code>RewriteEngine On
  #prevent hotlinking
  RewriteCond %{HTTP_REFERER} !^$
  RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?website.com [NC]
  RewriteRule \.(jpg|jpeg|png|gif)$ - [NC,F,L]
  
  # Redirect from website.com to www.website.com
  RewriteCond %{HTTP_HOST} ^ website.com [NC]
  RewriteCond %{HTTP_HOST} !^m.website.com [NC]
  RewriteCond %{REQUEST_URI} !errorPage
  RewriteCond %{HTTP_HOST} !^www [NC]
  RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1  [R=301,L]
  
  
  ErrorDocument 400 /errorPage400.php
  ErrorDocument 401 /errorPage401.php
  ErrorDocument 403 /errorPage403.php
  ErrorDocument 404 /errorPage404.php
  ErrorDocument 500 /errorPage500.php
  
  php_value session.gc.maxlifetime 604800
  php_flag register_globals 0
  php_flag session.use_only_cookies 1
  php_flag session.use_trans_sid 0
  
  
  &lt;IfModule mod_deflate.c&gt;
  #The following line is enough for .js and .css
  AddOutputFilter DEFLATE js css
  
  #The following line also enables compression by file content type, for the following list of Content-Type:s
  AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml
  
  #The following lines are to avoid bugs with some browsers
  BrowserMatch ^Mozilla/4 gzip-only-text/html
  BrowserMatch ^Mozilla/4\.0[678] no-gzip
  BrowserMatch \bMSIE !no-gzip !gzip-only-text/html 
  &lt;/IfModule&gt;
  
  &lt;IfModule mod_headers.c&gt;
  &lt;FilesMatch "\.(js|css|xml|gz)$"&gt;
  Header append Vary Accept-Encoding
  &lt;/FilesMatch&gt;
  &lt;/IfModule&gt;
  
  &lt;filesMatch "\.(jpg|jpeg|png|gif|swf)$"&gt;
  Header set Cache-Control "max-age=604800, public"
  &lt;/filesMatch&gt;
  # 1 WEEK
  &lt;filesMatch "\.(xml|txt|css|js)$"&gt;
  Header set Cache-Control "max-age=604800, proxy-revalidate"
  &lt;/filesMatch&gt;
  # 1 MIN
  &lt;filesMatch "\.(html|htm|php)$"&gt;
  Header set Cache-Control "max-age=60, private, proxy-revalidate"
  &lt;/filesMatch&gt;
  
  RewriteBase /
  
  # IF THE UA STARTS WITH THESE
  RewriteCond %{HTTP_USER_AGENT} ^(aesop_com_spiderman|alexibot|backweb|bandit|batchftp|bigfoot) [NC,OR]
  RewriteCond %{HTTP_USER_AGENT} ^(black.?hole|blackwidow|blowfish|botalot|buddy|builtbottough|bullseye) [NC,OR]
  RewriteCond %{HTTP_USER_AGENT} ^(cheesebot|cherrypicker|chinaclaw|collector|copier|copyrightcheck) [NC,OR]
  RewriteCond %{HTTP_USER_AGENT} ^(cosmos|crescent|curl|custo|da|diibot|disco|dittospyder|dragonfly) [NC,OR]
  RewriteCond %{HTTP_USER_AGENT} ^(drip|easydl|ebingbong|ecatch|eirgrabber|emailcollector|emailsiphon) [NC,OR]
  RewriteCond %{HTTP_USER_AGENT} ^(emailwolf|erocrawler|exabot|eyenetie|filehound|flashget|flunky) [NC,OR]
  RewriteCond %{HTTP_USER_AGENT} ^(frontpage|getright|getweb|go.?zilla|go-ahead-got-it|gotit|grabnet) [NC,OR]
  RewriteCond %{HTTP_USER_AGENT} ^(grafula|harvest|hloader|hmview|httplib|httrack|humanlinks|ilsebot) [NC,OR]
  RewriteCond %{HTTP_USER_AGENT} ^(infonavirobot|infotekies|intelliseek|interget|iria|jennybot|jetcar) [NC,OR]
  RewriteCond %{HTTP_USER_AGENT} ^(joc|justview|jyxobot|kenjin|keyword|larbin|leechftp|lexibot|lftp|libweb) [NC,OR]
  RewriteCond %{HTTP_USER_AGENT} ^(likse|linkscan|linkwalker|lnspiderguy|lwp|magnet|mag-net|markwatch) [NC,OR]
  RewriteCond %{HTTP_USER_AGENT} ^(mata.?hari|memo|microsoft.?url|midown.?tool|miixpc|mirror|missigua) [NC,OR]
  RewriteCond %{HTTP_USER_AGENT} ^(mister.?pix|moget|mozilla.?newt|nameprotect|navroad|backdoorbot|nearsite) [NC,OR]
  RewriteCond %{HTTP_USER_AGENT} ^(net.?vampire|netants|netcraft|netmechanic|netspider|nextgensearchbot) [NC,OR]
  RewriteCond %{HTTP_USER_AGENT} ^(attach|nicerspro|nimblecrawler|npbot|octopus|offline.?explorer) [NC,OR]
  RewriteCond %{HTTP_USER_AGENT} ^(offline.?navigator|openfind|outfoxbot|pagegrabber|papa|pavuk) [NC,OR]
  RewriteCond %{HTTP_USER_AGENT} ^(pcbrowser|php.?version.?tracker|pockey|propowerbot|prowebwalker) [NC,OR]
  RewriteCond %{HTTP_USER_AGENT} ^(psbot|pump|queryn|recorder|realdownload|reaper|reget|true_robot) [NC,OR]
  RewriteCond %{HTTP_USER_AGENT} ^(repomonkey|rma|internetseer|sitesnagger|siphon|slysearch|smartdownload) [NC,OR]
  RewriteCond %{HTTP_USER_AGENT} ^(snake|snapbot|snoopy|sogou|spacebison|spankbot|spanner|sqworm|superbot) [NC,OR]
  RewriteCond %{HTTP_USER_AGENT} ^(superhttp|surfbot|asterias|suzuran|szukacz|takeout|teleport) [NC,OR]
  RewriteCond %{HTTP_USER_AGENT} ^(telesoft|the.?intraformant|thenomad|tighttwatbot|titan|urldispatcher) [NC,OR]
  RewriteCond %{HTTP_USER_AGENT} ^(turingos|turnitinbot|urly.?warning|vacuum|vci|voideye|whacker) [NC,OR]
  RewriteCond %{HTTP_USER_AGENT} ^(libwww-perl|widow|wisenutbot|wwwoffle|xaldon|xenu|zeus|zyborg|anonymouse) [NC,OR]
  
  # STARTS WITH WEB
  RewriteCond %{HTTP_USER_AGENT} ^web(zip|emaile|enhancer|fetch|go.?is|auto|bandit|clip|copier|master|reaper|sauger|site.?quester|whack) [NC,OR]
  
  # ANYWHERE IN UA
  RewriteCond %{HTTP_USER_AGENT} ^.*(exabot|craftbot|download|extract|stripper|sucker|ninja|clshttp|webspider|leacher|collector|grabber|webpictures).*$ [NC]
  
  # ISSUE 403 / SERVE ERRORDOCUMENT
  RewriteRule . - [F,L]
  
  #when access is denied, allow access to just the error page and logo
  &lt;Files errorPage.*&gt; 
  Order Deny,Allow 
  Allow from All 
  &lt;/Files&gt;
  &lt;Files  logo.gif&gt;
  Order Deny,Allow 
  Allow from All
  &lt;/Files&gt;
  </code></pre>