Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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>
share|improve this question

2 Answers 2

<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>
share|improve this answer

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>
share|improve this answer
    
Cheers - I've tried Location, but I keep getting a 500 Internal Server Error when I reload the page –  williamsowen Mar 8 '12 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 '12 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 –  williamsowen Mar 8 '12 at 18:25
    
More descriptive error messages should be found in your error log. –  Ladadadada Mar 8 '12 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? –  Shane Madden Mar 8 '12 at 20:10

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.