.htaccess question

wankrtron

Gawd
Joined
Sep 27, 2004
Messages
761
i am by no means a "webmaster," more like "the web's bitch," but i am just really getting started here.

anyway, i have hosting, and i want to do the following:
i want to be able to im/email a link like www.domain.com/folder/picture.jpg so that when someone clicks it, they can look at that file, but when they try to go to www.domain.com/folder it asks for a username and password. i want anyone to be able to see the file if they have the complete url, but i only want certain people to be able to browse the directory.

right now i have it set up so that when you go to www.domain.com/folder/picture.jpg it asks for username and password, then after entering this, it displays the picture, but if you navigate to the directory, you are already logged in (obviously). is there a way to tweak a .htaccess file to allow it to do what i want? is .htaccess what i actually want to do this with? if so, what should it look like?

if you can help me here, that would be great. thanks.

edit:
oops...i didnt intend for those to be actual links....
 
i want to be able to im/email a link like www.domain.com/folder/picture.jpg so that when someone clicks it, they can look at that file, but when they try to go to www.domain.com/folder it asks for a username and password.

I'll tell you how to do this but...

i want anyone to be able to see the file if they have the complete url, but i only want certain people to be able to browse the directory.

If I remember, correctly, the whole directory will be password protected, not just the picture.



-Alright, add this to your .htaccess file:

Code:
AuthUserFile /www/u/username/.htpasswd
AuthGroupFile /dev/null
AuthName "test"
AuthType Basic
require user user1

u = First Letter of your username
username = Main FTP Username
test = Anything you want. It will be in that grey box that will pop up asking for authorization.

-user1 should be replaced with the user login which has the authorisation

If you want multiple users, it will be a tad different, but so far it looks like you want only one.

-Next, you need to make a .htpasswd file (created same way as you make the .htaccess)

-You need to add this line for every username you create
Code:
Username:Password

-Username can be whatever you want. The password should be encrypted. You can encrypt the password online.

-Upload .htpasswd above the htdocs folder (that is where there is the htdocs, cgi-bin etc..), in ASCII mode (this is what I did for MY domain, I don't know if other domains are the same)
 
er.... i was following, was following, got lost.

ok, i DO want to protect the directory, NOT the file. say i put 3 urls to images/files in my sig, i want anyone who clicks it to be able to see the image/file, but if someone tries to browse the directory they will need a username and password. im not gonna use it for links in my sig, but that is a simple example.

also, i DO want to be able to have multiple users, so is the "tad difference" IN the .htaccess, or by INCLUDING the .htpasswd?

from what i understand, it is AT LEAST extremely hard to password protect a single file, but thats not what im going for.

if i add that to my .htaccess file, i assume for it to work it cant have "Options -Indexes" in it right?

how would i go about encrypting the password online? i mean will the .htpasswd file have to contain a sting of characters, or how will it know what the encrypted pw looks like?

where i got totally lost is here:
EGGO said:
-Upload .htpasswd above the htdocs folder (that is where there is the htdocs, cgi-bin etc..), in ASCII mode (this is what I did for MY domain, I don't know if other domains are the same)
so far that has yet to register for me. am i totally missing something?

thanks for the help so far. im starting to get somewhere...i think.
 
I thought you'd get lost at that part. I guess that's something only my provider uses. You do that in your FTP. Lemme post a quick screenshot of what my FTP screenshot is like:

ftpscrnsht.jpg


Right there, you will see the "front door" of my site. The htdocs folder is basically houses ALL of my main stuff for my site (including the index.html). All I'm saying is that you should upload the .htpasswd file above the main folder where you upload your index.html.

As for doing multiple users change the last part of the code I gave you to:

Code:
require user user1
require user user2
require user user3 .. etc

Of course, change the 'user1' and 'user2' etc.. to any username desired.

Upload the .htaccess file to the folder you wish to password protect (so it's no duh you're not putting THIS .htaccess into the main folder where your index.html file is.) Do it in ASCII mode too.
 
ok, your htdocs is my domain name folder. i have a folder called domainname.com where my index and all my site goes into. i also have the logs folder and i have a mail folder at the same level as the domain folder, no cgi bin. im not that into it yet.

ok, im assuming that ASCII mode is something the FTP client can do to allow me to see the .htaccess file? cause ive been uploading and then changing the name of the file from htaccess.txt to .htaccess and it disappears. i havent been able to find an "ASCII Mode" yet though. am i way off here?

errr...ok i think i got the ASCII figured out. i have a mac client that has binary, ASCII and auto. so is it ok to leave it on auto, or should i choose ASCII specifically? and i can select the option to "show hidden files" which i can then see the .htaccess and .htpasswd files. ill give this all a try and see what happens.

thanks.
 
.htaccess files affect the directory, and all the files in them. You may be able to do what you want using some crazy mod_rewrite rules based upon the referrer (basically, the opposite of anti-hotlinking setups.. if they come directly in, let them see it, but if they try to click on a link from your site, deny them.. messy)

How about just making an index.html in the same directory as your files. People can get to the pictures if they know the name, but if you have an index.html file, they can't see the listing of all of them.
 
i would use an index, but it would deny the people i want to browse the directory the ability to do so. instead it would bring up an empty page.

i wouldnt figure this to be hard, but go figure. i just KNOW this is possible. i cant even rember how many sites ive been on that if you have a direct url you can say, veiw an image, but if you try to browse the directory it denys you and asks for u/p combo. does anyone else remeber seeing this type of thing?
 
ok well, i gave this a try, and it didnt work any differently than i already have. this also asked for a username and password with the direct url.

im hoping to give access to anyone who has a direct url, but restrict browsing the directory to those with a username and password.

anyone got any advice for me?
 
Back
Top