Table of Contents
![How to Use the .htaccess File](https://www.inmotionhosting.com/support/wp-content/uploads/2011/11/htaccess-file-1024x538.png)
The .htaccess
file is a powerful tool that helps control how visitors interact with your website. It can be used for security, redirects, URL rewriting, and more. In this guide, we’ll cover what the .htaccess
file does, where to find it, how to edit it, and how to troubleshoot errors it may cause.
What is the .htaccess File?
The .htaccess
file is a hidden configuration file used on Linux-based web servers, including InMotion Hosting’s Shared Hosting accounts. It allows you to make quick changes to how your site functions without modifying the main server configuration.
Since .htaccess
directly impacts how your website functions, always back up your .htaccess
file before making changes.
Where is My .htaccess File?
By default, the .htaccess
file is located in your website’s root directory:
Because it’s a hidden file, you’ll need to enable the Show Hidden Files option in cPanel’s File Manager to see it.
How to Locate and Edit .htaccess in cPanel
- Log in to cPanel.
- Click File Manager under the Files section.
- In the top-right corner, click Settings and check the box for Show Hidden Files (dotfiles). Click Save.
- Navigate to the
public_html
directory and locate the.htaccess
file. - Right-click the file and select Edit.
How to Create a .htaccess File (If Missing)
If you don’t see a .htaccess
file in public_html
:
- In File Manager, click +File in the top-left corner.
- Name the file .htaccess (with the dot at the beginning).
- Set the directory to
/public_html/
or your website’s document root. - Click Create File, then right-click it and select Edit.
What Can You Do With a .htaccess File?
The .htaccess
file offers a wide range of functions, including:
- Redirecting URLs – Forward visitors from one URL to another.
- Password-Protecting Directories – Restrict access to certain areas of your website.
- Blocking Specific Traffic – Prevent unwanted bots or users from accessing your site.
- Preventing Hotlinking – Stop other websites from embedding your images or files.
- Setting Default Pages – Specify which file (e.g.,
index.html
orindex.php
) loads first in a directory. - Forcing File Downloads – Make certain files download instead of opening in the browser.
- Customizing Error Pages – Set up custom 404 or 500 error pages.
- Rewriting URLs – Improve SEO by creating clean, user-friendly URLs.
Many of these settings can be configured automatically through cPanel, but advanced users can edit .htaccess
directly for more customization.
Troubleshooting .htaccess Errors
Since .htaccess
controls many aspects of your website, incorrect configurations can cause errors. If your website isn’t loading correctly, try these steps:
1. Temporarily Disable .htaccess
You can check if the .htaccess
file is causing an issue by renaming it:
- In File Manager, right-click
.htaccess
and select Rename. - Change the filename to
.htaccess.old
and save. - Reload your website.
- If the site loads correctly, an error in
.htaccess
was the problem. - If the issue persists, rename the file back to
.htaccess
and continue troubleshooting.
2. Check for PHP Configuration Issues
If your PHP settings aren’t applying correctly, you may need to make your php.ini
file recursive. See our full guide: How to Make php.ini Recursive.
Go Unlimited with Exceptional Shared Hosting
Upgrade your Shared Hosting today and take your business to the next level! Get unlimited NVMe SSD storage, cPanel, professional email and over $400 in savings.
Free Domain
24/7 Human Support
100% Money-Back Guarantee
Final Thoughts
The .htaccess
file is an essential part of website management, allowing you to control redirects, security settings, and more. Always back up your .htaccess
file before making changes, and if you run into issues, try renaming the file to troubleshoot errors.
Need more help? Check out our full .htaccess reference guide for advanced configurations.
Hello, I have edited the .htaccess file, but it does not take the code, I have tried several, and I get an error.
I need to compress, the codes with which I have tried are these, maybe they can help me
AddOutputFilterByType DEFLATE text / html text / plain text / xml text / css text / javascript application / x-javascript
————————-
AddOutputFilterByType DEFLATE text / xml
AddOutputFilterByType DEFLATE text / css
AddOutputFilterByType DEFLATE application / javascript
AddOutputFilterByType DEFLATE application / x-javascript
AddOutputFilterByType DEFLATE application / xml
AddOutputFilterByType DEFLATE application / xhtml + xml
AddOutputFilterByType DEFLATE application / rss + xml
I’m not clear on what you are trying to accomplish to be able to assist you. What is the error you are receiving? Which code are you using?
Hi there. I am a little confuse, so i need a little help to clean my folders.
My site was hosted in public_html folder (site1.com). So, i created a new version of site in a paralell subdomain (home/site2.com).
After upload site2.com files (new) to site1.com its showed some errors.
To solve it, support team helped me to redirect the url site1.com to site2.com. Everything is working fine. But now i have all same content in site1.com and site2.com
The problem is when i analysed in google pagespeed the result is an gzip problem because site1.com has a hard progress.
How can i eliminate site2.com completelly and return all content to site1.com without redirect and errors?
Its possible?
It can be done from you guys, since i am an stupid amateurs?
Hello!
It is possible to do this, however, the consequences of moving the directories are unpredictable due to the nature of how some sites work. With that said, you should be able to follow our guide on moving a WordPress site from the sub-directory (public_html/site2.com) to the main directory (public_html). Note: the guide assumes a WordPress site and that the main (public_html) directory is empty. Rather than deleting site1.com (public_html) files, you can simply rename the public_html directory to “public_html.old” then create a new public_html directory. Then, copy the files into the new public_html directory from public_html.old/site2.com/ for them to load on site1.com because that site will always load public_html by default.
Once you have followed those instructions, if any links need to be updated to correct images or other media content not loading, you can use the Velvet Blues Update URLs plugin. That plugin will make the process described in our guide on correcting images after moving a WordPress site, a lot simpler. If needed, after updating the URLs, everything should load fine on the site1.com site and you can then remove the public_html.old directory. I strongly recommend making a backup of your cPanel account before proceeding with any of these instructions.
In regards to Support, I would recommend submitting a ticket with a verified and detailed request of what you would like done. Although File Management and website configuration are beyond the scope of Support, they may be able to process your request if it is explicit enough and the technician is capable of completing the task. The guides/links I am providing to you are the steps that would need to be taken to accomplish what you want. If Support is unable to complete the task for you, the guides are there to provide as much assistance as possible. Note: Before submitting that request, you should make and download a backup of your cPanel account. I hope this helps!
Sincerely,
Carlos E
Hi…
I have a website in php.Now it has redesigned and launched, and number of pages reduced.Its redesigned in php itself.There is some changes in the url(name of webpages).Is there any need to redirect the url(from old webpage name to new one) in .htaccess file since it is already a php website?
One of the common reasons to redirect old pages would be in case any search engine had cached the old page names and those would now result in a 404 if clicked on.
The following errors were found :
How can I solve the error above observing during installation of BoldGrid for my domain.
Thanks,
Thuzar
Thuzar, I would recommend that you make sure that your .htaccess file actually exists, and that your permissions are set properly on it.
Thank you!
I’ve followed all the steps, and I’m not computer illiterate. But, I do NOT have the option to “check the box” to show hidden files. I accidentally switched to the “paper” theme on my cPanel, and now everything looks different.
Here is a link to our guide on How to show hidden files (htaccess) when using cPanel’s File Manager. The article has been updated for paper_lantern.
Thank you,
John-Paul
hello, i need your help… i have a web software on https://www.exampledomain.com, and i need all access inside the domain remais invisible on the navigation bar… no matter where i am on the site, its show only the domain name… is that possible with .htaccess?
It would be very unusual for an .htaccess file to affect the appearance of nav bars. We are happy to help you troubleshoot further, but will need some additional information. Can you provide a link to the site for testing?
Thank you,
John-Paul
We have a guide on how to redirect a domain without changing the URL that may provide a possible solution.
But, keep in mind this will require you to test and troubleshoot further.
Be sure to read the stipulations on the bottom of the guide.
Thank you,
John-Paul
Hi –
I created and uploaded a .htaccess file using the recommendations of a SEO site. My first attempt.. Must have done something wrong, as my site crashed. I deleted the file, the site came back, but my nav bars, which are in #include files are gone.
Hosting company won’t correct programming errors, and I’m at a loss where to look. Files look fine in Dreamweaver, but viewed locally and on the server, not so much.
Appreciate any help.
Thanks,
Nick
Hi,
I can able to redirect URL using .htaccess file but i cant mask server IP address with domain name.
https://mydomain.com is pointed to https://xxx.xxx.xxx.x:8080/abc.html (ip address) now i need to redrect /xyz/home.html to https://mydomain.com/xyz/home.html, i was able to redirect but i get redirected URL https://xxx.xxx.xxx.x:8080/xyz/home.html but i need to mask that ip address to https://mydomainname.com
For security purposes, we do not allow masking. The closest you can get is to add a parked domain. Specifically creating a parked domain for the primary domain will have sort of a masking effect.
I ever since the .htaaccess was changed, all the installed pluggins, mystile, wordpress are dissappeared. Is there a way to get them back without any re-installation?
Please advise?
Hello Teresa,
Did you rename the .htaccess file? If so, rename it back as it should contain the information to make those things work.
Kindest Regards,
Scott M
how does the .htaccess file and CPanel interact.
it appears .htaccess updates CPanel?
I do need an .htaccess for redirection of some files ; need to clarify “what goes where?”
can you advise?
the
Simply put, the .htaccess file defines extra options for the Apache web server. For more information on redirects, you could check our article on 301 redirects with .htaccess.
I am unable to find .htaccess file in c9ppanel
Hello remya,
The .htaccess file is hidden by default (hence the . at the beginning of the file name) which can be viewed by following the steps in this guide. Also you may not have a .htaccess file as it is not a default file pre-loaded to your account.
Kindest Regards,
TJ Edens
if i delete .htaccess by mistake what must i do
Hello yusuf,
Thank you for your question. If you deleted your .htaccess file, you can just create a new file and name it: .htaccess
Then add your rules back as needed.
If you have any further questions, feel free to post them below.
Thank you,
John-Paul
I am having question on .htaccess file. i accidentally override with another file content then my website come with errror, then i found the file and removed all the content inside .htaccess file then it started working fine but my question is when i deleted the content if i also deleted important document, pls tell me if there is some content deleted.
thank you
Hello biruhtesfa,
Thank you for your question. There is no way to tell if the content you deleted in the .htaccess file is important.
This is because websites can be coded many ways.
I recommend testing all aspects of your website (shopping carts, forms, scripts, etc.) to make sure it is still functioning after editing your .htaccess file.
If you have any further questions, feel free to post them below.
Thank you,
-John-Paul