.htaccess help please

.htaccess help please

Posted by: cyberman45
Posted on: 2007-10-25 08:15:00

I'm a newbie... With DreamHost I've discovered I can go to the "goodies" area of the panel to generate passwd protection for directories. Anyone know how this DreamHost feature handles the htpasswd file? I unerstand it should go above your web site so that visitors can't get to it. Does DreamHost place it there automatically.

Also if someone could give me an example or two on what needs to be entered in the first item... do you just put the name of the directory you want to protect there... or does it require the full path to the directory?

TIA

Re: .htaccess help please

Posted by: rlparker
Posted on: 2007-10-25 08:25:00

In reply to:

Anyone know how this DreamHost feature handles the htpasswd file? I unerstand it should go above your web site so that visitors can't get to it. Does DreamHost place it there automatically.


No, it doesn't. When you use this feature from the control panel, it puts both the .htaccess file and the .htpasswd file in the directory you are protecting.

If you still want to have the control panel build the files for you, you can do so and then move the created .htpasswd file above the web directory and edit the resultant .htaccess file to change the path to that file.

In reply to:

give me an example or two on what needs to be entered in the first item... do you just put the name of the directory you want to protect there... or does it require the full path to the directory?


Well, you never have to enter the "full" path, as the system prepends the domain name (which actually completes the path to that point), but you should put the directory name "beneath the domain name".

For example, if you want ro protect http://yourdomain.tld/private, then "/private" is what should be in the box.

Of you want to protect http//yourdomain.tld/images/private, then "/images/private" is what you should put in the box.

--rlparker

Re: .htaccess help please

Posted by: cyberman45
Posted on: 2007-10-25 09:22:00

okay... got it...many thanks

Re: .htaccess help please

Posted by: rlparker
Posted on: 2007-10-25 09:31:00

You are welcome, and good luck! smile

--rlparker

Re: .htaccess help please

Posted by: dwr
Posted on: 2007-10-25 12:58:00

I'd like to know more about where is best to actually place the htpasswd file. I've just let the panel create and place and had no idea that it could be viewed. I've just tried to pull mine up in the browser and it didn't work, but I'd like to here about potential issues!

Re: .htaccess help please

Posted by: rlparker
Posted on: 2007-10-25 17:08:00

Re: .htaccess help please

Posted by: cyberman45
Posted on: 2007-10-25 17:24:00

Re: .htaccess help please

Posted by: rlparker
Posted on: 2007-10-25 18:37:00

Re: .htaccess help please

Posted by: cyberman45
Posted on: 2007-10-26 09:11:00

Thanks again RL...

.htaccess is much clearer now... especially the "path" part. I will likely use various parts of the suggestions you've given me. Much appreciated!


Re: .htaccess help please

Posted by: rlparker
Posted on: 2007-10-26 09:12:00

You are welcome, and I'm glad you found at least some of that to be useful. smile

--rlparker

Re: .htaccess help please

Posted by: dwr
Posted on: 2007-10-27 23:19:00

That was one NICELY explained essay there... you should no doubt put that into the wiki!

MUCH appreciated, RL... I definitely have a much better understanding of this and it triggered some understandings in related areas.

I think judging from that I'll just let the panel do em as it wishes with what I am protecting now, as it is not truly sensitive material (just stuff I don't want my wedding video clients to run up on!), but that information should come in very handy in the future.

Again, thanks a TON for the essay!!!
dwr

Re: .htaccess help please

Posted by: rlparker
Posted on: 2007-10-27 23:45:00

Thank you for your kind and gracious comments, dwr! smile I realize that I get a bit verbose at times; it is nice to know that occasionally someone benefits from such excesses of verbiage.

I think you'll likely be fine just leaving those files where the Control Panel tool puts them, and if you should decide to change them later, hopefully some of the info in that tome will be helpful. wink

--rlparker

Re: .htaccess help please

Posted by: kaveshla
Posted on: 2007-11-03 06:53:00

Hi to all.. RL some great insights into the world of .htaccess..

I'm fairly new to web building, lived off the basics and now moving forward.. I've been trying to understand .htaccess & .htpasswd and why it's necessary..

Currently, for the sites I work on I would have 2 users max on the system and in that case is the .htpasswd file really necessary in my case? I have no problem logging into Dreamhost to make changes.

I'm really looking for a way to prevent my folders being seen - for example, if i were to type.. http://www.mysite.com/img the entire list of images would show up.

Also I'm on mac, so terminal is optional to write the .htaccess file but I'm finding it hard to find out how to do so online..

Thanks for your help!

Re: .htaccess help please

Posted by: rlparker
Posted on: 2007-11-03 13:00:00

In reply to:

Currently, for the sites I work on I would have 2 users max on the system and in that case is the .htpasswd file really necessary in my case? I have no problem logging into Dreamhost to make changes.


Probably not. Apache authentication using .htaccess and .htpasswd is generally used to keep visitors from seeing a dir, page, etc. without completing a user/pass dialog - and really doesn't have any effect of "making changes" unless it is protecting a web script that could be used via a browser for such a purpose.

In reply to:

I'm really looking for a way to prevent my folders being seen - for example, if i were to type.. http://www.mysite.com/img the entire list of images would show up.


That is easily done a couple of different ways. You can do it with a line added to an .htaccess file that impacts the directory in question. In your case it could be " /home/username/mysite.com/img", or any "uptree" directory, as .htaccess files affect the directory they are in and any directory *below* that directory. To supress the display of the "index" of files in a directory, the line to enter in the .htaccess file is:

Options -Indexes

This information, and a lot of additional useful material about .htaccess files is available on the DreamHost Wiki:

http://wiki.dreamhost.com/KB_/_Unix_/_.htaccess_files

This page also has a section on how to create .htaccess files. Why don't you take a look at that page, and if you still need help creating an .htaccess file after reading through that, post back with a more specific question and I'm sure we can get you sorted. wink

--rlparker


Re: .htaccess help please

Posted by: kaveshla
Posted on: 2007-11-05 10:41:00

Thanks a lot it worked. I did go to that page before but it somehow did not make as much sense...

Silly question, Should I put this file in each of the subfolders? I get that everything in the folder images and inside of that will be protected - but the folders 'alongside' images.

Re: .htaccess help please

Posted by: rlparker
Posted on: 2007-11-05 13:48:00

You're welcome, and I'm glad you have it working. smile

In reply to:

Silly question, Should I put this file in each of the subfolders? I get that everything in the folder images and inside of that will be protected - but the folders 'alongside' images.


It's not really a silly question. An .htaccess file affects the directory it it is any any directory beneath it (unless overridden by a subsequent .htaccess file in a sub-folder). So, you could either put that same .htaccess file in each "sibling" ("alongside") directory, or put it *above* that level of subdirs.

If the "parent" directory of those "sibling" directories already has an .htaccess file (and many sites do!), then just adding that line to the existing .htaccess file will do the trick.

An easy way to make sure that directory are suppressed for your entire site is to just put that line in an .htaccess file at the "base" directory of your site. wink

--rlparker

Re: .htaccess help please

Posted by: cyberman45
Posted on: 2007-11-07 08:08:00

Hello R.L.....

A little more advice please on .htaccess... and sorry this is long.

I thought I had it down based on your previous advice but alas I don't have it working as it should. So with your patience, I will give an example here of what I'm trying to do and hopefully you can straighten me out.

I have created a site using wysiwyg web design software. I've published the site and it is on the esprit server and working fine. So now comes the .htaccess part.

In my site I have a members page. I am setting up links for individual clients... and for example I want the owner of Widgits Inc to link to a directory that will allow him to download the audio files in "his" directory from esprit to his local machine. I don't want him to see anyone else's directory and I don't want anyone else to be able to see his.

The protected directories have to be under the "your domain.tld" directory... right?

Also, when creating the links in the wysiwig... the only appropriate options for links seem to be "file" or "audio file."
If I understand correctly, when the Widgits guy clicks on his member link, .htaccess is supposed to make a password dialog box pop-up right? I though I had it set-up correctly but when I tested the link, it went straight to playing the audio file without asking for a password.

In trying to set all this up... I've apparently either not set up the directory tree correctly... left something out of the .htaccess file (by the way I used one of those automatic generator utilities to create the code)... or didn't do the link properly... or maybe all of the above. Should I as you suggested earlier, use DreamHost panel to generate .htaccess and then move things around?

In creating the directory where the Widgit Inc. audio files will be located... do I create that directory on the FTP server... or create it on my local machine and then upload it?

Or do I have to create an additional web site page to link to? I doesn't seem that would be the way to go because the audio files would not all end up in the one directory... they would just be separate files under the main web site directory.

I had better stop now before you run out of patience!!

Many thanks





Re: .htaccess help please

Posted by: rlparker
Posted on: 2007-11-07 13:43:00

Let's see if I can help get this sorted out. Having carefully read your post, one thing that comes to mind is that thing *might* actually be working for you as expected, but you are not able to see it because of the way Apache basic authentication works with your browser.

Once a user has successfully passed an authentication dialog, apache will *not ask again* while that browser is open unless/until the .htaccess file is changed. This can easily lead you to believe, when you are setting things up, that the authentication routine is not working when it actually *is*; only by closing your browser and trying *again* to connect to a protected area can you be *sure* that it is, or is not working.

The use of wysiwyg software might be complicating your issue slightly in some subtle way, though it really should not have anything to do with the authentication stuff. I am, however, confused as to what you mean by "the only appropriate options for links seem to be "file" or "audio file" - a link is just a link, adn I'm not sure how/what/why the software makes any distinction as to what the link is to.

In reply to:

In my site I have a members page. I am setting up links for individual clients... and for example I want the owner of Widgits Inc to link to a directory that will allow him to download the audio files in "his" directory from esprit to his local machine. I don't want him to see anyone else's directory and I don't want anyone else to be able to see his.


If I understand this correctly, that "members' page" is *not* protected, but only lists links to each member's "private directory", and *those directories* are what are to be protected via .htaccess. Is that correct?

In reply to:

The protected directories have to be under the "your domain.tld" directory... right?


Yes, they must be "somehwere" beneath your "web base directory" to be accessible from the web, but they do not have to be *immediately* beneath your "top" directory.

In reply to:

If I understand correctly, when the Widgits guy clicks on his member link, .htaccess is supposed to make a password dialog box pop-up right? I though I had it set-up correctly but when I tested the link, it went straight to playing the audio file without asking for a password.


This is a bit confusing to me, as I initially had though you were just providing links to the members *directory* as opposed to an individual file, but either way, if the file is placed in a directory that is protected by .htaccess, then the authentication dialog should be presented the *first time* a user click a link the links to the file.

In reply to:

In trying to set all this up... I've apparently either not set up the directory tree correctly... left something out of the .htaccess file (by the way I used one of those automatic generator utilities to create the code)... or didn't do the link properly... or maybe all of the above. Should I as you suggested earlier, use DreamHost panel to generate .htaccess and then move things around?


It could be any, or a combination of, those things that are causing your unexpected behavior - it's really hard for me to guess from your description what may be happening. Also, what "automatic generator utility" are you using to "create the code"?

You could certainly consider just using the DreamHost provided Control Panel tool fro password protecting directories to get you started easily (that what it is for) and then move thing around if you desire, or leave them as DH sets them up.

In reply to:

In creating the directory where the Widgit Inc. audio files will be located... do I create that directory on the FTP server... or create it on my local machine and then upload it?


It should make absolutely no difference at all - as long as the directory ends up on your server the end result should be the same.

In reply to:

Or do I have to create an additional web site page to link to? I doesn't seem that would be the way to go because the audio files would not all end up in the one directory... they would just be separate files under the main web site directory.


I'm confused by this question; whether or not you create a separate page or not is not relevant, only the *location* of the page/file/etc. to be protected - they must be in a protected directory for the authentication to take place, whether a file, or a page, it matters not.

In reply to:

I had better stop now before you run out of patience!!


Ha ha , well, I still have some patience left, and I'd like to help you, but I admit I'm confused about the details of what you are describing in a few places, and "the devil is in the details." You might consider posting a url to your site (using dummy data files) so we can see what you have structured rather than just relying upon your descriptions - sometime stuff is lost in the translation. Alternately, you are welome to PM me with a url if you would like for me to look at it but do not wish to publish your url in public.

What "wysiwyg" software are you using? Some such software (most notably iWeb) tends to "mess with" a sites directory structure as it "builds a web", and this could be having an impact on your efforts.

In a nutshell, what it seems you are trying to do is to have a structure that looks something like this:

                                http://yourdomain.tld
___________________________|__________________
| |
http://yourdomain.tld/member1 http://yourdomain.tld/member2
| |
http://yourdomain.tld/member1/file1 http://yourdomain.tld/member1/file2

and you want the member1 and member 2 directories to be password protected.

To do this, you put the .htaccess file with the authentication directives in *those* directories. Then, if you wish, you can either put a page in each of them (index,.html) to link to each of the files, or just let the files display in a directory listing for the user to "click" - either way, those files will not be visible to anyone who does not pass the password dialog.

Does any of this help at all?

--rlparker

Re: .htaccess help please

Posted by: cyberman45
Posted on: 2007-11-07 14:41:00

R.l.

Thanks for dissecting my rambling questions. Since posting them I've have some success. I actually got one of the directories protected and I successfully logged in... but just as you said, when it didn't work the next time I assumed that it was not working. After much frustration, I closed the browser and next time, it worked correctly again.

Then possibly getting too big for my britches, I tried setting up another protected directory. I tried to make it a carbon copy, with a different directory name of course, but the second one bypassed htaccess and went straght to the files I was trying to protect. There must be quite a few bald newbies out there who have pulled out all of their hair in furstration.

Another strange thing, my web host is DreamHost... and I used their htaccess utility to generate the access code and encrypted passwords. In the process I moved the password file above the web site directory and changed the path to it in the access code... and when I was creating the second one... it seemed that the utility "re-encrypted" the password for the first directory I created and now it won't take the password. sheeesh this is maddening. Ever run across something like that before. I think I need to go lay down. aaarrrggghhh!!!

And yes, my site has a members page with multiple link buttons... they link to directories on my local machine which contain the files I am trying to protect. I created identical directories on the server and upload to them. Could that be part of the problem... I wouldn't think it would matter but should the directories I'm trying to protect on the server have a different name?

Thanks again.

Re: .htaccess help please

Posted by: rlparker
Posted on: 2007-11-07 15:20:00

In reply to:

I actually got one of the directories protected and I successfully logged in... but just as you said, when it didn't work the next time I assumed that it was not working. After much frustration, I closed the browser and next time, it worked correctly again.


Okay, so *that* is the model for what you want to do for each directory. Duplicate what/how you did things for this directory for the *other* directories, and you should be golden.

In reply to:

I tried to make it a carbon copy, with a different directory name of course, but the second one bypassed htaccess and went straght to the files I was trying to protect.


While I can't be certain without seeing it, I suspect that this might be the result of a misplaced directory; if that directory was *beneath* the prior, then the behavior you experienced is to be expected. wink

In reply to:

I used their htaccess utility to generate the access code and encrypted passwords. In the process I moved the password file above the web site directory and changed the path to it in the access code... and when I was creating the second one... it seemed that the utility "re-encrypted" the password for the first directory I created and now it won't take the password. sheeesh this is maddening. Ever run across something like that before.


Well, once you start moving around the output of the utility, you risk "confuzzling" the panel utility. Per the philosophy of "learning to walk before trying to run", I suggest sticking with the DH COntrol Panel .htaccess utililty output *as is* (even if it stores the .htpasswd file in the target directory) and getting that to work for each involved directory before mucking about with changing the locations/names of the .htpasswd files. I talked about this at length in a prior post in this thread.

In reply to:

... my site has a members page with multiple link buttons... they link to directories on my local machine which contain the files I am trying to protect. I created identical directories on the server and upload to them. Could that be part of the problem... I wouldn't think it would matter but should the directories I'm trying to protect on the server have a different name?


As long as those "links" are "relative" instead of "absolute" (so they are properly translated to their correct location of the server, it shouldn't make any difference. In fact, doing it that way you would need to make certain that the directory names *were* the same (or change the links for the "buttons") for it to work.

--rlparker

Re: .htaccess help please

Posted by: cyberman45
Posted on: 2007-11-09 10:51:00

Hello...

Well with your generous help and quite a bit of trial and error, I'm closer to solving this than ever before.

In your last post you wrote...
"Well, once you start moving around the output of the utility, you risk "confuzzling" the panel utility. Per the philosophy of "learning to walk before trying to run", I suggest sticking with the DH COntrol Panel .htaccess utililty output *as is* (even if it stores the .htpasswd file in the target directory) and getting that to work for each involved directory before mucking about with changing the locations/names of the .htpasswd files. I talked about this at length in a prior post in this thread."

I understand what you're saying here... but I'm striving to have that single Passwd file above my web site folder and an .htaccess folder in each "member" directory, making the path in each access file point to the single passwd file.

I soon realized that every time you ask the DH Panel utility to protect a new directory, it also re-processes all the directories you've already set-up... overwriting the access file with the original path... putting the password file inside the directory again instead of above the site directory... and re-encrypting all the previous passwords. At least that's what it appears to do in my case.

What I tried as a work-around...
On my local machine, I created an .htaccess file with the path I want... and a passwd file with the user:password entries I have so far. And instead of using the panel... I ftp the access file into the directory to be protected... manually updated the passwd file and ftp'd it to the one on the server.

When I go to my web site, and click on each member link, the authorization dialogue pops up for each one... BUT once I enter the user name and password for one of them... then the others go straight to the file without asking for a login!!!

Is there a way to make my work-around work... because I'd REALLY prefer not to have to change the path in each and every access file each time I add a new member log-in plus having to delete all the passwd files from each directory.

And imagine down the road as I hopefully get more clients, this would become a gargantuan pain.

Is there any way to make my approach work with dreamhost... is there another utility somewhere that will provide my approach?

Also, one other question, the "files list" on the server cuts off the end of the file name... i.e. doesn't show the file extension that tells my clients whether audio files are wav or mp3. Is there a way to widen the columns?

As always I would greatly appreciate your guidance... hope I haven't worn out my welcome

Tom

p.s. I'll search for your earlier thread on The Panel and .htaccess



Re: .htaccess help please

Posted by: oodways
Posted on: 2007-11-09 11:34:00

In reply to:


When I go to my web site, and click on each member link, the authorization dialogue pops up for each one... BUT once I enter the user name and password for one of them... then the others go straight to the file without asking for a login!!!


I have been following this thread with great interest.

I may be completely wrong here, but if all of the passwords for all of the directories are in the same htpasswd file, and all of the htaccess files (in all of the directories) point to that one password file, then authenticating for one directory authenticates for all of them.

Regards,
Rudy


Re: .htaccess help please

Posted by: cyberman45
Posted on: 2007-11-09 12:00:00

Hi Rudy,

I was wondering if that could be a problem. I've read quite a few articles outside of the DreamHost site and they say having the single passwd file outside or above your web site directory is the way to go because if it's inside... i.e. in the same folder as the access file (which is where DreamHosts control panel puts it by default) it's too easy for others to get to, which defeats the whole purpose of protection.

I'm hoping RL will weigh in one more time on all this... he really seems to have a handle on how this access deal works.

Thanks for your reply!!

Re: .htaccess help please

Posted by: rlparker
Posted on: 2007-11-09 12:52:00

In reply to:

I'm striving to have that single Passwd file above my web site folder and an .htaccess folder in each "member" directory, making the path in each access file point to the single passwd file.


You can certainly do that, by combining all the user/password hashes into a single .htpsswd file but are you sure that is what you want to do? Doing that would make *any* valid user/pass combination in the .htpasswd file "work" for *any member directory*. There fore, while user A could use his user/pass to enter his own member directory,m he could also use it to enter menber B's directory (and I don't think that is what you had in mind).

In reply to:

When I go to my web site, and click on each member link, the authorization dialogue pops up for each one... BUT once I enter the user name and password for one of them... then the others go straight to the file without asking for a login!!!


Exactly !(see my first paragraph above) - *unless* you close the browser between each attempt. Apache sees that a user that in the indicated .htpasswd file has already successfully authenticated *for the directory requested* (whichever one it is) because the .htaccess files in each directory *all point to the same .htpasswd file*.

Earlier in this thread I described a away to set things up similar to what you describe, but that method relies on different named .htpsswd files for each directory.

There are many ".htaccess authentication management utilities" out there, a visit to hotscripts.com would point you to several free/commercial alternatives.

--rlparker


Re: .htaccess help please

Posted by: rlparker
Posted on: 2007-11-09 12:55:00

Oops! I'm sorry I didn't notice your answer before I responded (I responded directly from my email notice of the post) - WHat you said is exactly correct, and I apologize for the "me too - what he said" reply. wink

--rlparker

Re: .htaccess help please

Posted by: cyberman45
Posted on: 2007-11-09 13:27:00

R.L... You wrote...

"You can certainly do that, by combining all the user/password hashes into a single .htpsswd file but are you sure that is what you want to do? Doing that would make *any* valid user/pass combination in the .htpasswd file "work" for *any member directory*. There fore, while user A could use his user/pass to enter his own member directory,m he could also use it to enter menber B's directory (and I don't think that is what you had in mind)."

So based on what you say here... the solution would be to have a different passwd file above the web site for each directory containing an access file... with each passwd file having a unique name... and each access file having a unique path that points only to the corresponding user:encrypted password file.

Do I have it right?

thanks





Re: .htaccess help please

Posted by: rlparker
Posted on: 2007-11-09 15:36:00

Yes. smile

Again, in my earlier post in this thread I demonstrated a way to do essentially that, except that I put all those assorted .htpasswd files in a single *directory* "above my main web accessible directory" (a sister, or sibling, if you will to the domain's main web directory) to reduce the clutter in my main user dir and make it easyh to keep them organized.

--rlparker

Re: .htaccess help please

Posted by: cyberman45
Posted on: 2007-11-09 17:05:00

RL

By Jove, I've got it!!! Eureka!!! Man it's tought being a newbie. Thank you for being there to drag me along... kicking and screaming... at my PC.

Don't know whether you caught my other question... regarding the columns in the file list on the FTP server. The first column is so narrow the file extensions are not visible and my clients will have difficulty knowing whether an audio file is a wav or an mp3. Is there a way to "widen" the column so the entire file name is visible?

Many thanks


Re: .htaccess help please

Posted by: rlparker
Posted on: 2007-11-09 17:13:00

Heh, good deal and congratulations! I'm gald you have that sorted. smile

In reply to:

Don't know whether you caught my other question... regarding the columns in the file list on the FTP server. The first column is so narrow the file extensions are not visible and my clients will have difficulty knowing whether an audio file is a wav or an mp3. Is there a way to "widen" the column so the entire file name is visible?


Yep, there are actual several approaches you could take. There are many scripts out there that provide various kinds of "customized" directory displays (see hotscripts.com), but what the hey, since you are on an .htaccess role, this should meet your needs just fine:

Showing long file names in Apache directory listings

--rlparker


Re: .htaccess help please

Posted by: cyberman45
Posted on: 2007-11-09 18:19:00

Thanks for the long filenames tip.

Tried it and it worked perfectly.

You Da Man!!

Re: .htaccess help please

Posted by: rlparker
Posted on: 2007-11-09 18:25:00

You are welcome, and I'm very glad to see you are getting things set up the way you want. smile

--rlparker

Tags: dreamhosthtpasswdpasswdtiahtaccessgoodiesnewbie