Disallow all user agents except one using .htaccess?

Posted by Kian Mayne on Pro Webmasters See other posts from Pro Webmasters or by Kian Mayne
Published on 2012-08-28T10:08:02Z Indexed on 2012/08/28 15:51 UTC
Read the original article Hit count: 382

I've been struggling to get this .htaccess working. The aim is to disallow all user agents besides my app. The app sends a GET request with a user agent of lets say 'AcmeUpdater'.

Whenever I try to navigate to any file in the folder, I get a 500 - Internal Server Error. Here are the rules I'm using:

<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_USER_AGENT} !^KMUpdaterClient*
RewriteRule .* - [F,L]
</IfModule>

I have updated the .htaccess file as suggested in the answer by Nick, and restarted Apache. After trying a couple of different things, it seems that just the presence of a .htaccess is causing the 500 error. I'm getting nothing in the error logs.

The .htaccess file at the document root looks like the following:

<IfModule mod_rewrite.c>
Options +FollowSymLinks
ErrorDocument 404 /index.php?error=404
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
</IfModule>

So I realised that the error logs were in chronological order rather than the reverse chronological I expected (Oops!).

The error I'm getting is: </IfModule> without matching <IfModule> section. I removed the </IfModule> and still I get that error. Ideas?

© Pro Webmasters or respective owner

Related posts about apache

Related posts about htaccess