7

I have used code like this in apache configuration to protect locations with password

<Location ~ "/admin.*">
    AuthType Basic
    AuthName "Protected Area"
    AuthUserFile /home/user/public_html/.htpasswd
    Require valid-user
</Location>

is there a way to do the same thing using an htaccess file?

the locations I want to protect don't really exist on the filesystem, it's locations available thanks to mod_rewrite

dimvic
  • 231
  • 2
  • 7

2 Answers2

3

Yep, with <Files> (or <FilesMatch>): http://httpd.apache.org/docs/2.2/mod/core.html#files

Edit: "Note that unlike Directory and Location sections, Files sections can be used inside .htaccess files. This allows users to control access to their own files, at a file-by-file level."

Mark Wagner
  • 17,764
  • 2
  • 30
  • 47
  • 1
    I'm not sure this does what dimvic is looking for -- A directive can point to something that's not on the filesystem (e.g. ``) in which case .htaccess wouldn't work. It's probably viable if the area to be protect "really exists" though... – voretaq7 Oct 21 '10 at 19:35
  • I suspect they are files. – Mark Wagner Oct 21 '10 at 20:10
  • 3
    the area doesn't really exist, this is the problem, i need to protect an area that exists thanks to mod_rewrite – dimvic Oct 22 '10 at 12:44
  • If the area doesn't exist (on the filesystem) then there is no place to put an .htaccess file so what you are asking is impossible. – Mark Wagner Oct 22 '10 at 17:34
  • I was thinking that it could possibly be done with an htaccess placed in the site's root folder – dimvic Mar 16 '12 at 16:53
0

Yes it's possible to do so put a htaccess in the file you want to moderate the access. Put the same text as in the configuration file. Make sure that your conf files will read .htaccess.

Gopoi
  • 547
  • 5
  • 21
  • I meant add it to one of directory that you need to moderate. – Gopoi Oct 21 '10 at 18:48
  • 2
    tags are not accepted in htaccess, it's context is "server config, virtual host" http://httpd.apache.org/docs/current/mod/core.html#location – dimvic Mar 16 '12 at 16:50