1

I have a htpasswd file, works fine - in my htaccess I have:

<Limit GET POST>
require valid-user
</Limit>

Which works, login/passwd shows up fine when you reach the root of website. However I need to limit this so the login/passwd will only appear when the user reaches for example http://mywebsite.com/appear/here/* - so basically when the user reaches /appear/here/* it should show..

I've looked at Can htpasswd be used to restrict access to a URL rather than a specific folder? - but still can't seem to figure it out..

Have tried:

<Files /appear/here/*>
require valid-user
</Files>

<Directory /appear/here/*>
require valid-user
</Directory>

2 Answers 2

1

<Directory> is for a physical directory path on your server; or you can use <Location>.

One of these:

<Directory /path/to/webroot/appear/here>
    Require valid-user
</Directory>

Or:

<Location /appear/here>
    Require valid-user
</Location>
1

The <Files > directive will try to match the filename, not the path leading up to the filename. Hence a <Files > directive with a slash in it is invalid. It is often used to match the extension on a filename.

The <Directory > directive is for directories relative to the root of the filesystem. So you probably want <Directory /var/www/docroot/appear/here>.

Since URIs don't always match filesystem paths, you may be better off with a <Location > directive, since these are matched against the URI.

<Location /appear/here>
  require valid-user
</Location>
7
  • Cheers - I've tried Location, but I keep getting a 500 Internal Server Error when I reload the page Mar 8, 2012 at 17:47
  • Do you have more in your config than just that Require ? The relevant part of the docs says "Require must be accompanied by AuthName, AuthType and AuthBasicProvider or AuthDigestProvider directives, and directives such as AuthUserFile and AuthGroupFile (to define users and groups) in order to work correctly."
    – Ladadadada
    Mar 8, 2012 at 18:19
  • Yes, I have: AuthUserFile /path/to/my/.htpasswd AuthGroupFile /dev/null AuthName RESTRICTED AuthType Basic - This is at the top of my htaccess, with the Location directives below it.. Have also tried placing this information within the Location directives too - but still I receive a 500 error. My htacess file is the standard bundled with Drupal 6 Mar 8, 2012 at 18:25
  • More descriptive error messages should be found in your error log.
    – Ladadadada
    Mar 8, 2012 at 18:28
  • 1
    @williamsowen Oh, this is in an .htaccess file? Why not just put the restrictions in an .htaccess in the restricted location and drop the extra blocks, then? Mar 8, 2012 at 20:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .