You may have visited one of your web page’s URLs and found a list of files like the one included in this post? It can be embarrassing and also pose a security threat to your website. The reason behind this output/display is that if you create a new directory (or folder) on your website, and do not put an “index.html” file in it, you may be surprised to find that your visitors can get a directory listing of all the files in that folder. For example, if you create a folder called “incoming”, you can see everything in that directory simply by typing “http://www.example.com/incoming/” in your browser. No password or anything is needed.
In this article, you can configure your web server so that it does not show a directory listing by default.
Many people today are building their own websites for some reason. Many build websites for a simple online brochure and some are for online stores. That is not bad though. Your website is one of the important factors in your business. So whether you are building it as a simple online brochure or an online store, setting it up in a proper way it is somewhat like as important as naming your own child. So it is just a nice move to invest time in setting up your website properly.
Before we get into the technical side of things, here are some definitions to digest;
According to Mozilla Developer Network, The term web server can refer to hardware or software, or both of them working together.
On the software side, a web server includes several parts that control how web users access hosted files. At a minimum, this is an HTTP server. An HTTP server is a software that understands URLs (web addresses) and HTTP (the protocol your browser uses to view webpages). An HTTP server can be accessed through the domain names of the websites it stores, and it delivers the content of these hosted websites to the end user’s device.
At the most basic level, whenever a browser needs a file that is hosted on a web server, the browser requests the file via HTTP. When the request reaches the correct (hardware) web server, the (software) HTTP server accepts the request, finds the requested document, and sends it back to the browser, also through HTTP. (If the server doesn’t find the requested document, it returns a 404 response instead.)
.htaccess files provide a way to make configuration changes on a per-directory basis on a web server
To hide/show your directory:
Via Web Hosting Account
- Log in to the Control Panel of your Website Hosting plan
- Click File Manager in the File Section
- Click public_html
- Check for .htaccess, If it does not exist, make sure that it is not hidden from your view.
- If it is hidden check the top right-hand corner for the settings icon, to reveal “show hidden files” or some such thing, make sure you enable it.
- Make a Backup of the .htaccess File by downloading it to your computer to make sure you have two(2) copies of the .htaccess file, the one you are about to modify, and a pristine copy of the original. The backup is useful in case you accidentally make an error later.
- If you’ve managed to get the .htaccess file, search for the edit option and navigate to the editor (eg an ASCII text editor).
- Add the following line to your .htaccess file.
Whenever you modify your .htaccess file, you should always check that your website still works after uploading it. It is very important to note that the .htaccess can make or ruin your website and should be used with caution.
If anything goes wrong, delete the .htaccess file on your website and your site should work again. For those who had an existing .htaccess on the site before, upload the backup copy to the site. If all goes well, you should get a “Forbidden” error or some error reminding you that you don’t have access to view such resources.
If you enjoyed this piece and would like to share your thoughts, I would be glad to reply your comments.