To create a .htaccess file in cPanel, open File Manager in the cPanel dashboard, navigate to the site document root (usually public_html), click +File, name the file exactly .htaccess with the leading dot, and save a generated or hand-written ruleset into it. cPanel hosts run Apache, or an Apache-compatible fork such as LiteSpeed, for most shared plans, and the .htaccess file is the per-directory configuration file that Apache reads on every request. Because the filename starts with a dot, cPanel hides it by default; you must enable Show Hidden Files in the File Manager settings before the icon becomes visible. You can also create the file outside cPanel on your computer and upload it through File Manager, FTP, or SSH, but creating it inside File Manager keeps everything in one place and lets you edit rules without leaving the browser. Apache applies .htaccess rules only if AllowOverride permits them on your hosting account, and many shared hosts restrict that policy.

Where the .htaccess File Lives in cPanel
In cPanel, the .htaccess file lives in the site document root: public_html for the main domain, or a subdirectory inside it for an addon domain, subdomain, or subfolder install. cPanel's Apache build reads .htaccess from whichever directory a request enters and walks up through parent directories until it finds a rule or runs out of paths to check. One file at the top of public_html is enough for most sites; an additional .htaccess inside a subfolder only overrides rules for that branch.
Because the filename begins with a dot, File Manager hides it by default. Click the gear icon in the top-right corner, choose Settings, and tick Show Hidden Files (dotfiles). The existing .htaccess, if any, then appears like any other file. Do the same in your FTP client: FileZilla, Transmit, and Cyberduck all expose a "show hidden files" toggle in their connection or view settings. For SSH users, ls -a or ls -la reveals the file from the command line.
The hosting environment controls what the file is allowed to do. Apache ignores .htaccess unless AllowOverride grants at least FileInfo for rewrite rules and Limit for access controls. Shared hosts usually allow FileInfo and Limit, but a few disable one or both. If a directive produces a 500 Internal Server Error instead of behaving as expected, AllowOverride is the first thing to check through your host's documentation or support channel.
Generate the Rules With Htaccess Generator
Hand-writing a .htaccess that handles HTTPS canonicalization, directory-listing control, and a custom 404 page invites typos that loop requests or take the site offline. The Htaccess Generator accepts a single canonical hostname plus optional flags, then produces a small, auditable Apache 2.4 file in plain text. Every line corresponds to a documented Apache 2.4 behavior, the file is short on purpose, and adding untested rules by hand is exactly the situation the tool is designed to prevent.
Enter the final hostname exactly as it should appear in visitors' URLs, for example https://www.example.com. The input must contain only the public origin: no credentials, port, path, query string, or fragment. The generator always builds an HTTPS target, escapes the dots in the hostname for the negative condition, and assembles one fixed-host 301 RewriteRule that preserves the original REQUEST_URI. A 301 redirect tells browsers and search engines to treat the new location as the canonical one, but it also caches aggressively, which is why staging matters before production.
The optional checkboxes cover the two other document-root concerns. Enabling directory listing disablement adds an Options -Indexes line, which asks Apache not to emit a file index when no index document exists. Enabling a local 404 path adds one ErrorDocument rule pointing to a path beginning with /; external URLs, query strings, fragments, and whitespace are rejected because they can produce loops or trigger errors outside the host's control. Leave both unchecked if your hosting environment does not permit those directives; the file still works for the HTTPS redirect on its own.
How to Create and Upload a .htaccess File in cPanel File Manager
- Sign in to your cPanel account at https://yourdomain.com:2083 or your provider's custom URL, then open File Manager from the Files section.
- In the top-right Settings gear, enable Show Hidden Files (dotfiles) and pick the document root (public_html for the main domain) in the left pane.
- Click +File in the top toolbar, type .htaccess — including the leading dot — in the New File Name field, and confirm the location is the document root.
- Select the new file in the list, click Edit, and paste the contents produced by the Htaccess Generator. Apache treats the dotfile name literally, so any extra characters such as .htaccess.txt break the file.
- Click Save Changes, then close the editor. The new file is saved into public_html the moment you save.
- Return to the home directory and click Reload to confirm the icon is still listed after save; some cPanel builds briefly cache the directory listing.
If a .htaccess already exists, the panel instead shows an Edit button on that row. Open it for editing through File Manager or a code editor plugin rather than re-uploading, so a single failed write does not leave the site without any file. The same procedure works for an addon domain or a subdomain: navigate to that domain's document root, which cPanel places inside public_html or as a sibling directory, and follow the same steps there.
Merging New Rules With an Existing .htaccess
Replacing an existing .htaccess with a fresh file is the fastest way to lose CMS routing, authentication, cache headers, compression, or IP access control. Back up the current file before touching anything: open it, select all, copy the contents into a local text file with the timestamp in the name, and store the copy outside the account (a local folder, not a subdirectory of public_html).
Open both files side by side. The generator's output covers only mod_rewrite for the HTTPS redirect, Options -Indexes, and ErrorDocument, so each of those blocks must coexist with whatever the CMS already produces. Most front-controller patterns (WordPress, Joomla, Drupal, Ghost's proxy block) wrap around if (mod_rewrite.c) markers and end with a final RewriteRule. Insert the canonical hostname block above the CMS block so the redirect runs first and is not hidden by later rules. Keep the Options line at the top of the file unless the CMS specifies conflicting values, and place the ErrorDocument line after both blocks so error handling sits at the bottom of the cascade.
After a successful merge, test every page, not just the home page. Permalinks, sitemap requests, RSS feeds, login pages, and admin areas all rely on rewrite rules. If any URL returns 404 when it previously returned 200, restore the backup and recheck the rule order. For a deeper walkthrough of merging canonical-host rules with CMS-side routing, see How to Create a .htaccess File for HTTPS Redirects.
What the Three Optional Directives Actually Do
A short table is more useful than prose for seeing what each block does and where it tends to fail.
| Directive | What it does | When it can break |
|---|---|---|
| RewriteEngine on + canonical 301 | Forces every request to the fixed HTTPS hostname while preserving REQUEST_URI | 500 error if AllowOverride does not include FileInfo; redirect loop if Apache sits behind a TLS proxy |
| Options -Indexes | Stops Apache from listing directory contents when no index document exists | 500 error if AllowOverride does not permit the Options directive |
| ErrorDocument 404 /path | Serves a local path as the 404 response body | 404 loop if the target page itself triggers an error; ignores external URLs |
Validate Apache and Test Every Request Path
Apache treats a syntactically plausible .htaccess very differently depending on the server configuration that hosts it. Run apachectl -t (or service apache2 configtest) on the shell when you have root or sudo access; you do not need to reload the server to test a config file. Most cPanel shared accounts do not expose the shell, so a configtest there means asking the host, or running the file on a local Apache and staging server before pushing it to production.
Test against these URL types from a private browser window:
- HTTP version of the home page: should 301 to HTTPS.
- HTTPS version of an inner URL with query string: should land on the same path and query on HTTPS.
- The alternate host (e.g. the bare domain or a www-less variant): should 301 to the canonical host.
- A URL that does not exist, like /does-not-exist: should serve the configured 404 page locally, not the hosting default.
- An asset path such as /wp-content/uploads/sample.jpg: should resolve without triggering any rule.
If any request loops, returns 500, or returns the wrong host, restore the backup from the local copy made earlier and recheck the merge. The Apache mod_rewrite introduction and the custom error responses documentation are reliable references when a rule refuses to behave as documented.
When the Site Sits Behind a TLS Proxy
Many cPanel-style deployments place Cloudflare, a CDN, or a load balancer in front of Apache. The HTTPS condition generated for a direct Apache-to-internet site relies on mod_ssl and assumes that HTTPS reaches Apache as native TLS. When a proxy terminates TLS and forwards plain HTTP, the condition always matches, and every request loops through the redirect.
There are three workable approaches. The simplest is to issue the HTTPS redirect at the proxy itself: Cloudflare's Edge Redirects, a Load Balancer page rule, or an Nginx virtual host at the proxy origin are all reasonable places to enforce 301s. The second is to adapt the rewrite condition to a trusted, overwritten header that the proxy sets on each request, such as X-Forwarded-Proto, and check that value rather than mod_ssl. The third is to disable the per-directory rewrite and configure a virtual host Redirect in the main Apache configuration, which the Apache documentation often recommends because it is faster and not subject to .htaccess quirks.
Whichever path applies, the redirect decision should live in the layer that actually sees the user's protocol. Per-directory rules cannot reach that decision if the layer in front of them rewrites the request scheme, so removing the HTTPS block from the generated .htaccess and handling the redirect upstream is usually the cleanest fix on a proxy-backed cPanel site.
Related reading: htaccess to Nginx: The Limits of Automated Conversion.