Log in

View Full Version : Lack of sample .htaccess code



Viking warrior
08-17-2011, 07:11 AM
I run a number of public web pages voluntarily and now wish to make one accessible only by password. The tutorials say "insert the .htaccess file above the root file (to maintain security)" but don't explain how to do this. As an example I have a website http://www.lancsarchsoc.org.uk/ (I don't need to secure this one) - where would I place the .htaccess file? Is there a tutorial somewhere with sample code, which I can read, please?

djr33
08-17-2011, 01:50 PM
A .htaccess file is named just that. It's just an extension and has no filename. It automatically works without anything more than just creating it.

You can search for lots of information about what kind of code you can place inside a .htaccess file. For example, you can require a password or block certain files. I'm guessing the tutorials you mentioned gave you some examples of the code, or you can find some in other places. An empty .htaccess file will do nothing (though it won't hurt either).

The .htaccess file is placed inside the directory for which it will be relevant (and for any child directories as well). So if you place it in your root folder it will apply to the entire site (the highest level folder with your main index page, called public_html for some servers), or you can put it in a specific folder so it will only apply to that area. You can also layer .htaccess files like this, and the most local file takes precedence.

Viking warrior
08-17-2011, 03:46 PM
Hi Daniel: Thanks for your message. Unfortunately (me being a bit thick) it doesn't really answer my question. My domain (using the previous example) is www.lancsarchsoc.org.uk. The default is .../index.html. I want surfers to see the default page but not be able to download some specific information from it without logging in, for which I need password control. My ISP says "document root: /homepages/46/d194010594/htdocs/las". I have no idea what that means. You mention my root folder - where is that? You are correct in saying that the tutorials suggest a lot of code - they are very helpful - but they don't show how to insert it in the root folder! More help, please!

djr33
08-17-2011, 03:56 PM
The root folder (technically root directory-- directories for websites, folders for computers) is the highest level folder for your domain. In other words, yoursite.com is the root folder, and, for example, yoursite.com/example is a subdirectory (subfolder). The configuration varies by server, but it's very easy to figure this out: wherever your main index page is, that's your root directory. The "index.html" file you mention is likely in that location. It may be the long confusing path you posted, and that's fine. Just go where you would normally upload your main files (html files, images, etc) for the root of your domain and place the .htaccess there.


----
Note: if you incorrectly place a .htaccess file that has, for example, a line that disables the directory for viewers, then you may break your website. This is temporary, and once you delete the .htaccess file it will work again. .htaccess only applies for going to your website, not for editing it, so you can go in through FTP (or some other file manager) and fix the situation. In reality, it may take some time for the browsers to understand that the restriction has been lifted. If this happens just wait a bit or use a different computer while waiting.
This is unlikely but possible, so I am mentioning it to avoid panic if you think you have destroyed your site. It won't cause any permanent harm. And again, this only applies if you are adding code that blocks your site. In fact, it will probably happen with any .htaccess you add (such as requiring a password, blocking certain files, etc.), and it's normal to experience a slight delay while changing .htaccess. The effects will of course just be those that are specified in the file. (If the .htaccess file is completely confusing to the server it might effectively disable it as well, but by removing it you'll fix that too.)

Viking warrior
08-17-2011, 07:42 PM
Daniel - you are truly a gent! If I was in Illinois I'd buy you a beer or three (I might be in the USA next year, if only to escape these goddam' Olympics). I will try what you advise. Who knows? I may even get it right. Thank you very much.:):)