cPanel & Hosting How-Tos The .htaccess File Explained: Common Rules and Fixes
The .htaccess file is a small but powerful configuration file that controls how your web server handles requests — redirects, HTTPS, access rules, error pages and more. It’s used on Apache and LiteSpeed servers (including ours). Here’s what it does, with copy-ready rules.
Where to find it
.htaccess lives in your site’s root folder, usually public_html. It’s a hidden file, so in cPanel File Manager you may need to turn on Settings → Show Hidden Files (dotfiles) to see it. Each folder can have its own .htaccess that applies to that folder and below.
Always back up
.htaccessbefore editing. One wrong line causes a 500 error for the whole folder.
Common rules
Force HTTPS
Send every visitor to the secure version:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
More on this in force HTTPS on your website.
Redirect a page (301)
Redirect 301 /old-page.html https://yourdomain.com/new-page
See how to set up a redirect in cPanel for the point-and-click version.
Redirect to www (or non-www)
RewriteEngine On
RewriteCond %{HTTP_HOST} ^yourdomain\.com [NC]
RewriteRule ^(.*)$ https://www.yourdomain.com/$1 [L,R=301]
Custom error pages
ErrorDocument 404 /404.html
ErrorDocument 500 /500.html
Block access to a file
<Files "wp-config.php">
Require all denied
</Files>
Block an IP address
<RequireAll>
Require all granted
Require not ip 203.0.113.50
</RequireAll>
For a friendlier way, use cPanel’s tool — see how to block an IP address in cPanel.
The WordPress default block
WordPress manages its own .htaccess section for permalinks. It looks like this and should be left intact:
# BEGIN WordPress
...
# END WordPress
If your pretty URLs stop working, go to Settings → Permalinks and click Save — WordPress rewrites this block cleanly.
Fixing a broken .htaccess
If the site shows a 500 error after an edit:
- In File Manager, rename
.htaccessto.htaccess-bak. - Confirm the site returns.
- Fix the offending rule, or (WordPress) resave Permalinks to regenerate it.
Edit with confidence
Every Web Hosting and WordPress Hosting plan runs LiteSpeed (which reads .htaccess like Apache), with File Manager and backups so you can edit safely. If a rule isn’t behaving, our support team can check it for you. For diagnosing related errors, see read your website error logs.
Frequently asked questions
Where is the .htaccess file?
It sits in your website's root folder (usually public_html) on Apache/LiteSpeed servers. It is a hidden file, so in cPanel File Manager you may need to enable 'Show Hidden Files' to see it. Each folder can have its own .htaccess.
Why did my site break after editing .htaccess?
A single wrong line in .htaccess causes a 500 error for the whole folder. Always back up the file before editing. To recover, rename the broken .htaccess, confirm the site returns, then fix the rule - for WordPress, resave Permalinks to regenerate a clean file.
Do I need .htaccess with WordPress?
Yes. WordPress uses .htaccess for its permalinks (pretty URLs) and often for caching and security rules. If permalinks stop working, regenerating .htaccess by resaving Settings - Permalinks usually fixes it.