Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

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?

share|improve this question
    
Comment line by line (and restart/reload apache each time) and you will see what is wrong. –  j0k Aug 28 '12 at 10:15
add comment

1 Answer

Finally realised what the problem was when, after deleting the tag in both files, the error "Invalid command '\xef\xbb\xbf

EF BB BF = BOM

Moral of the story: Always check your encoding* and hex dump of your files when you get weird issues.

*On Notepad++ you can use the Encoding -> Encode in UTF-8 without BOM option to remove it

share|improve this answer
2  
Thanks for posting your solution. Glad you found a fix! –  Nick Aug 28 '12 at 11:37
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.