Skip to content
Free website migration on every plan, done by our team.Learn more ›
Performance

.htaccess basics: redirects, HTTPS and security rules

What the .htaccess file does on Apache and LiteSpeed hosting, safe examples for HTTPS, www and redirects, and how to recover if an edit breaks your site.

Short answer: .htaccess is a configuration file in your website folder that Apache and LiteSpeed servers read on every request. It controls redirects, HTTPS, caching headers and access rules. One typo can cause a 500 error, so download a backup before every edit.

Where to find it

It lives in public_html and starts with a dot, so it's hidden by default. In cPanel's File Manager, open Settings and tick Show hidden files.

Useful examples

Force HTTPS

RewriteEngine On RewriteCond %{HTTPS} off RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Redirect one page

Redirect 301 /old-page/ https://yourdomain.com/new-page/

Block access to a sensitive file

<Files wp-config.php> Require all denied </Files>

Rules of thumb

  1. Back up first, then change one thing at a time.
  2. Test immediately after saving.
  3. Don't duplicate rules that a plugin already adds, which is a common cause of redirect loops. See fix too many redirects.

If you break the site

Restore your backup copy or remove the last change. A 500 error right after an edit almost always means a syntax error in .htaccess. See fix a 500 error.

Frequently asked questions

Does Nginx use .htaccess?

No. Nginx uses its own configuration files. LiteSpeed and Apache read .htaccess.

Can WordPress edit .htaccess?

Yes. WordPress and some plugins write rules between their own marker comments; leave those blocks intact.

Should I use .htaccess or cPanel for redirects?

cPanel's Redirects tool writes the same rules for you and is safer for simple redirects. See 301 vs 302 redirects.

Ready when you are

Host it where it performs

NVMe speed, offshore privacy and a written SLA — live in minutes on AuroxHost.