Blog · WebJi® India

How to Edit the .htaccess File

Quick answer: The .htaccess file sits in public_html and starts with a dot, so it is hidden. In cPanel open File Manager, enable Show Hidden Files, right-click .htaccess and choose Edit. Copy the file to .htaccess.bak first. Save, then load the site; if it returns 500, rename the backup back.
✓ In business since 2005✓ INR + GST billing✓ 24/7 Email Support — avg reply < 60 min
Young Indian woman in a kurti registering a domain name on her laptop at a wooden desk with a sketch notebook — how to edit htaccess file

What the .htaccess file is and where it lives

The .htaccess file is a plain text file of Apache or LiteSpeed settings that applies to one folder and everything under it. It sits in the site's document root, usually public_html, and its name starts with a dot, so a file manager hides it until you switch hidden files on. Edit it by hand only after you have copied it.

  • Location — /home/youruser/public_html/.htaccess for the main domain. An addon domain has its own folder and its own file.
  • Permissions — 644. Files at 777 make Apache refuse the request.
  • Scope — every request in that folder and below, including subfolders, unless a subfolder has its own file.
  • Server — Apache and LiteSpeed read it. Nginx ignores it completely, whatever you write.

WordPress keeps a block between # BEGIN WordPress and # END WordPress and rewrites it whenever permalinks are saved. Anything you add inside that block disappears the next time someone clicks Save on the permalink screen.

Back up the file before you open it

One invalid line takes the whole site down, including wp-admin, so the copy is not optional. It costs ten seconds.

  1. In cPanel open Files, then File Manager, and click Settings at the top right.
  2. Tick Show Hidden Files, save, and open public_html.
  3. Right-click .htaccess, choose Copy, and name the copy .htaccess.bak in the same folder.
  4. Download a second copy to your computer. If the account is later suspended or the disk fills, the local copy is the only one left.

If there is no .htaccess at all, the site is either not using pretty permalinks or the file was deleted. WordPress recreates it when you open Settings, Permalinks and click Save Changes, so do that before creating one by hand.

Open the file in File Manager, FTP or SSH

Three routes reach the same file. Pick the one you already have access to.

RouteHow to open itWhen it is the right choice
cPanel File ManagerRight-click .htaccess, then Edit, then Edit again on the encoding promptMost edits, no client needed
FTP or SFTPConnect with FileZilla, open public_html, right-click the file, View/Edit, then save and uploadThe dashboard is down or File Manager will not save
SSHcd ~/public_html, then nano .htaccessLong files, or a rule you want to edit and test fast

File Manager's code editor keeps line endings as they are. A desktop editor is riskier: saving in Word or in an editor set to Windows line endings can add characters Apache rejects, and a UTF-8 byte-order mark at the top of the file is enough to return 500 on every page.

Edit one block at a time, and know what belongs here

Add a single rule or a small block, save, and load the site before adding the next. Editing twenty lines and then testing turns one mistake into twenty suspects.

  • Comments — a line starting with # is ignored. Use them to date the change and say why.
  • Order — rules run top to bottom. Specific paths go above general ones, or the general rule catches the request first.
  • Case — directive names are not case sensitive, paths and patterns usually are. Add [NC] when you want a pattern to ignore case.
  • Modules — a directive from a module the server does not load causes a 500. Wrap optional blocks in <IfModule mod_rewrite.c>.

Some jobs do not belong in this file at all. Changing the PHP memory limit in .htaccess is overridden by the panel's PHP settings on most shared accounts, and a redirect for one page is a two-click job under Domains, then Redirects. Use .htaccess for rules the panel cannot express: pattern redirects, headers, hotlink blocking, IP denies and compression.

Test the change, then roll back if it breaks

Load the home page and one inner page in a private window straight after saving. Then check the response code of the URL you meant to change, so you know the rule fired rather than the cache answering.

curl -I https://example.com/the-page/

A 500 means Apache rejected the file. Open File Manager, delete or rename .htaccess, and the site returns at once, because the folder falls back to the server defaults. Then restore .htaccess.bak and add your rule again, more carefully.

What you seeWhat it usually means
500 on every page right after savingSyntax error, unknown directive, or a byte-order mark. Restore the backup.
403 on every pageA deny rule is too broad, or permissions on the folder changed.
Site fine, rule does nothingThe file is in the wrong folder, or AllowOverride is off for that directory on the server.
File Manager cannot save the fileOwnership or permissions. Edit over FTP or SSH instead.
Change vanishes after a plugin saveSomething else writes the file. Keep your block outside the WordPress markers.

Why the file is hidden, missing or locked

A dot at the start of a name means "hidden" on Unix, and most file managers obey that. That is the only reason a working .htaccess appears to be missing. Turn on Show Hidden Files and it is there.

If the file genuinely is not present, the site is probably using plain query-string URLs, where WordPress has nothing to rewrite. Saving permalinks recreates it. A file you create by hand has to be named exactly .htaccess, saved as plain text, and set to 644.

A host can also switch AllowOverride off, which makes Apache ignore the file without any error. On shared hosting that is a support question, not something a rule can fix. On Linux hosting with cPanel the directive is on for public_html by default.

Editing .htaccess on a WebJi® account

Every WebJi® Linux plan is cPanel with File Manager, so the route above works without an FTP client. The file sits in public_html, and the panel's MultiPHP Manager handles the PHP version and memory settings that people often try to force through .htaccess.

If an edit returns 500 and the backup rename does not bring the site back, email support@webji.services with the rule you added and the time. Support is 24/7 by email in Hindi and English, with an average first reply under 60 minutes. Do not call the office phone for this; it is a business-hours line.

For the rule syntax itself, the 301 redirect guide covers redirects in detail, and the cPanel hosting page covers what the panel can do without touching the file.

Frequently Asked Questions

How do I edit the .htaccess file safely?

Copy .htaccess to .htaccess.bak first, open the original in cPanel File Manager with Show Hidden Files on, and change one block at a time. Save, load the site, and only then add the next rule. If the site breaks, rename the backup back.

Where is the .htaccess file located?

In the document root of the site, which is public_html on a cPanel account. An addon domain has its own folder and its own .htaccess. The file is hidden because its name begins with a dot, so enable Show Hidden Files to see it.

Why is my .htaccess file not working?

Four causes cover most cases: the file sits in the wrong folder, AllowOverride is off on the server, another system overwrote your block, or the rule never matches because the path is wrong. Check the path first, then confirm the rule survived a plugin save.

What happens if I delete .htaccess?

Apache falls back to its defaults, so a plain HTML site usually keeps working. A WordPress site loses pretty permalinks and every inner URL returns 404 until you open Settings, Permalinks and click Save Changes, which writes a fresh file.

Can I edit .htaccess from the WordPress dashboard?

Only with a plugin that adds an editor, such as a file editor under Tools or an SEO plugin's file editor. WordPress core has no built-in .htaccess editor, which is deliberate: one syntax error locks you out of wp-admin.

Does .htaccess work on Nginx?

No. Nginx does not read .htaccess files at all, so a rule that works on Apache does nothing there. On Nginx the same redirect or header has to go in the server block, which means asking the host to apply it.

Need help with this?

WebJi® support does it for you — free. Talk to our Jaipur team →