.htaccess and .htpasswd authorisation

Discussion in 'Software' started by almightymaster, Dec 14, 2005.

  1. almightymaster

    almightymaster Private E-2

    I'm trying to create a passworded directory on my website. My .htaccess file looks like this, and works:

    RewriteEngine on

    RewriteBase /

    #this sends people coming to the root to the search page - lovely and invisibly
    RewriteRule ^$ hidden/search.php [L,QSA]

    AuthType Basic
    AuthName "Search Admin"
    AuthUserFile /path/to/my/file/.htpasswd
    AuthGroupFile /dev/null
    <Files hidden>
    Require user valid-user
    </Files>


    All good.

    However, I want this to block all traffic to the URL "hidden/*" if they can't provide a password. Looking at the Apache spec, Location or LocationMatch appear to have a syntax which means I can simply replace "Files" with one or other of them, and it will work. But when I do, I get a 500 server error...what gives?

    Here's my code which generates the error:

    RewriteEngine on

    RewriteBase /

    #this sends people coming to the root to the search page - lovely and invisibly
    RewriteRule ^$ hidden/search.php [L,QSA]

    AuthType Basic
    AuthName "Search Admin"
    AuthUserFile /path/to/my/file/.htpasswd
    AuthGroupFile /dev/null
    <Location hidden>
    Require user valid-user
    </Location>


    Cheers!
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds