Change .htaccess File on HostGator
If you are keeping a website and you are aware of your webhost, then you might have heard the word "htaccess". In this article, I am going to talk about only htaccess.
What Is htaccess File?
Htaccess is a file which is used in apache server configuration. The real configuration file name is .htaccess (pronounced as dot-htaccess). Please not the dot (.) before htaccess. So from now onwards, whenever I refer the htaccess file anywhere in the article, you need to understand that I am talking about .htaccess file.
You might be thinking why the dot is appended before htaccess. Well, the simple answer is, it's a configuration file in the Linux system and it needs to be secure. All the files starting with dot (.) in the Linux system are hidden files. That's why the dot is appended before htaccess file name.
Where Is .htaccess File Located?
You will most probably find the htaccess file under the root directory of any website. If you are using a web hosting provider which is using cPanel then your root directory is public_html.
If you have specially set separate root directory for any domain then you will find the .htaccess file under that root directory. For example, I have set root directory for this domain to /home/user/hgpqr.com . So .htaccess file for my domain is located at /home/user/hgpqr.com/.htaccess .
If you can't see the .htaccess file under your root directory then also it's fine. You will have to then create one text file under your root directory and give it the name .htaccess.
Why .htaccess File is Needed?
Htaccess is an apache configuration file. You can adjust parameters for apache server using that configuration file. Apache server has two configurations files. One is global configuration file and another is .htaccess file which is local for every site.
In web hosting, every customer has different needs. The customer doesn't have an access to the global configuration file but every customer has an access to the .htaccess file. All customers can set the local configurations according to their needs.
Whenever any parameter is set in both .htaccess file and in global configuration file, the value for that parameter is counted from .htaccess file. For example, HostGator sets ErrorDocument 404 parameter and shows some 404 page. If you create the same entry in .htaccess file and use some other file name then your given file name will be displayed on 404 error and HostGator's global parameter page is ignored.
How To Edit .htaccess File?
You have three ways to edit .htaccess file.
1) Use the SSH to connect to the server and then use vi command to edit the .htaccess file online. You will have to learn the vi command first to make any changes in .htaccess file.
2) Create a simple text file at your local system using notepad. Save it as .htaccess file. Make the necessary entries in the file and save it. Upload the file to your document root.
I prefer the first options because I know how to use vi command but if you are not technical person then you can use the second method to make changes in .htaccess file.
You can also use the third method to make necessary changes in .htaccess file. You can find the third method in the following video.
Make sure that you have made correct entries in .htaccess file before saving. Your site won't be accessible if you make a syntax error in .htaccess file and save it.
I hope now you have enough understanding to change the .htaccess file.
You can get a minimum of 25% discount on HostGator hosting. Just use any of the discount codes from hgcarjd and you can save money on your hosting bill.
Back to Hostgator Tutorials
Go to Home