- Details
- Created on Friday, 01 August 2014 16:57 01 August 2014
With an .htaccess file, you can quickly restrict the use of images from your website on other sites, add a custom 404 page, block an IP address, redirect a web page to a different web page, etc.
The .htaccess file has been around since the early days of the Internet and is still in use on millions of web servers. While most users don’t use it, it’s a really powerful tool, which can help you a lot in many different situations.
It is vital for any webmaster to get to know what they can do with an .htaccess file.
Today, we will show you how to do all those things with the Web Hosting Control Panel.
Hotlink Protection
Go to Advanced -> Hotlink Protection. From there, simply select a website and the exact path, if you want to protect a specific folder only. Here is the code for doing it manually:
<Files "login.php">
Order deny,allow
Deny from all
AuthName "htaccess password prompt"
AuthType Basic
AuthUserFile /web/askapache.com/.htpasswd
Require valid-user
</Files>
Please note that this is just an example and the path displayed above may be different for your particular hosting account.
Keep in mind that you will also need to create an .htpasswd file with the password inside. It has to be stored in the same folder as the .htaccess file. Don’t enter the password in plain text – use MD5 encryption.
Here is an MD5 encryption tool you can use - http://www.md5online.org/md5-encrypt.html.
Custom Error Pages
Go to Hosted Domains and right-click on any of your hosts. Select Edit. Now you will see the most popular error pages. They are currently set to Default, but you can pick a custom page – simply select the Custom URL option and enter the URL of the 404 page that you want to use. To manually add an error page, use the following code:
ErrorDocument 404 /path/to/error/page.html
IP Blocking
In your Hepsia Control Panel, go to Advanced -> IP Blocking. From there you can quickly block a specific IP from accessing a given website. Additionally, you can use the following code in your .htaccess file:
ErrorDocument 403 http://www.my-website.com/
Order deny,allow
Deny from all
Allow from 107.45.18.3
This is just a small list of what can be done with an .htaccess file. The folks from AskApache have prepared a very detailed list of examples at http://www.askapache.com/htaccess/htaccess.html. Make sure to check the code snippets out – they are frequently updated.
Don’t forget to also have a look at our .htaccess generator, which is located in the Advanced section of the Hepsia Control Panel. It will generate a custom .htaccess file with all the options that you want to use.
Keep in mind that if you are using a script-based website (a WordPress-based website, a Joomla-based website, etc), you already have an .htaccess file, which has been generated automatically by the application. Instead of generating a new one, you are better off editing your existing .htaccess file.
Kind Regards,
Support team