A .htaccess file is a small, hidden configuration file that controls how your web server behaves for a specific folder and everything inside it. On shared hosting, it is the main way you can change certain server settings, like redirects or custom error pages, without needing full server access. You will usually come across it when following a tutorial that asks you to "add this to your .htaccess file," or while troubleshooting a website error.
What You Can Use It For
A single .htaccess file can control several things at once. Common uses include:
- Redirecting old pages to new URLs, or an entire domain to another address
- Forcing all visitors to use HTTPS instead of HTTP
- Showing a custom page when a visitor hits a 404 or other error
- Password-protecting a folder
- Blocking specific IP addresses from reaching your site
- Turning off directory listing so visitors can't browse your folder contents
- Setting browser caching rules to help your site load faster
Many of these tasks also have a dedicated tool in your control panel (redirects, IP blocking, and directory protection all have their own menus), so you rarely need to write .htaccess rules by hand unless a specific tutorial or plugin asks you to.
Where to Find It
The file lives inside your website's root folder, usually public_html, and sometimes inside subfolders if you want rules to apply only there. Because its name starts with a dot, it's treated as a hidden file and won't show up until you turn on hidden files in your file manager.
In cPanel
- Log in to cPanel and open File Manager.
- Click the Settings gear icon in the top-right corner.
- Tick Show Hidden Files (dotfiles) and click Save.
- Open the public_html folder. You should now see .htaccess listed.
- Right-click it and choose Edit (or Code Editor) to make your changes.
In DirectAdmin
- Log in to DirectAdmin and open File Manager.
- Navigate to your domains folder, then into your domain's public_html folder.
- If .htaccess isn't listed, enable the option to show hidden files, usually found in the file manager's view or settings menu.
- Click the .htaccess file and choose the edit option to open it in the built-in editor.
If no .htaccess file exists yet in the folder, you can create one by adding a new file and naming it exactly .htaccess, with the leading dot and no file extension after it.
Before you edit .htaccess, download a copy to your computer first. A single typo in this file, like a missing space or an unclosed rule, can bring your entire website down with an "Internal Server Error 500" until it's fixed. If that happens, restoring your backed-up copy gets the site working again while you figure out the correct rule.
A Few Tips
- Add one change at a time and check your website after each save, so you know exactly which line caused a problem if something breaks.
- Rules are read from top to bottom, so the order they appear in the file matters.
- If you're using WordPress, the plugin managing your permalinks or redirects often rewrites this file automatically. Avoid manually editing the WordPress-generated section unless you know what you're changing.
For more on managing files directly in your hosting account, see How to Use the cPanel File Manager or How to Use the DirectAdmin File Manager.