Mobile app version of vmapp.org
Login or Join
Kristi941

: Disallow all user agents except one using .htaccess? 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

@Kristi941

Posted in: #Apache #Htaccess #HttpCode500 #ModRewrite #UserAgent

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?

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Kristi941

1 Comments

Sorted by latest first Latest Oldest Best

 

@Angie530

Finally realised what the problem was when, after deleting the tag in both files, the error "Invalid command 'xefxbbxbf

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

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme