I've configured basic Apache authentication for certain areas of a website that only administrators should have access to. Most web applications make this convenient by putting their admin pages in a subdirectory, so I configure authentication for the directory, such "/goodapp/admin". The problem is that some applications instead rely on the query string, eg.
/badapp/index.php?page=admin
Is there any way I can configure Apache to require authentication for a URL like this, based on the query string?
I did some research on this, but I don't think that Apache will let you match on the query string in a way that will allow you to conditionally require authentication. You could match on a directory or file, but not on items in a query string AFAIK (unless you are doing URL rewriting). This makes sense because you probably don't want application logic sitting in the webserver configuration.
What you could do is prepend any scripts that have admin capabilities with a check like this:
The second time around,
PHP_AUTH_USER
should be set and so$isLoggedIn
will be true. Then in your code, you can conditionally display/allow the admin functionality.