.htaccess File Reference List: Rules, Fixes, and Uses

The .htaccess file controls how Apache serves the directory it lives in, along with every folder beneath it. This reference groups our .htaccess guides by what you are actually trying to do: redirect traffic, restrict access, speed up delivery, change how files are served, or repair a file that broke your site.

What the .htaccess File Does on Your Server

A .htaccess file is a distributed configuration file. You place it in a directory, and the directives inside apply to that directory and all of its subdirectories, which is why a single rule in public_html can affect an entire site (Apache HTTP Server documentation).

New to the file itself? Start with What is the .htaccess file and what do I use it for? before working through the rules below.

Find the Right Guide Fast

Your GoalSection to Read
Send visitors to HTTPS or a new URLRedirects and URL Rewriting
Block an IP, country, or bad actorRestricting Access
Speed up delivery or stop a page from cachingCaching and Delivery Speed
Change the default page or hide extensionsFile Handling
Replace the default 404 screenCustom Error Pages
Fix a 500 or 403 error you just causedFixing a Broken File

Before You Edit .htaccess, Do These Three Things

Small syntax mistakes in this file take down the whole site, not just one page. Three habits prevent most of the support tickets we see:

  1. Copy the existing file before you change it. A rollback takes seconds when you have the original.
  2. Turn on hidden files in your editor. The leading dot hides it by default, so use How to show hidden files (.htaccess) in cPanel’s File Manager if the file seems to be missing.
  3. Test in a browser with cache disabled after every change. Cached redirects, especially 301s, are difficult to undo once a browser stores them.

How Do You Redirect URLs and Force HTTPS With .htaccess?

Redirect rules are the most common reason people open this file. They also carry the most SEO weight, so the difference between a temporary and permanent redirect matters.

How Do You Restrict Access With .htaccess?

Access rules work at the server level, which means a blocked request never reaches WordPress, PHP, or your database. That makes .htaccess a useful first layer against brute force login attempts and scrapers.

Blocking Visitors by IP, Country, or Behavior

Protecting Individual Files and Directories

Which .htaccess Rules Control Caching and Delivery Speed?

Two directives do most of the performance work. Compression shrinks what leaves the server, and cache headers stop returning visitors from downloading assets they already have. The reverse matters too: some pages should never be cached at all.

Speeding Up Delivery

Turning Caching Off Where It Causes Problems

Both compression changes show up quickly in tools like PageSpeed Insights or GTmetrix, which makes them easy to verify.

How Do You Control the Way Files Are Served?

These rules change what the server does with a request before your application ever sees it.

How Do You Set a Custom Error Page?

A default Apache error screen tells visitors nothing and gives them nowhere to go. How to Set a Custom 404 Page Using .htaccess walks through pointing missing URLs at a branded page with search and navigation, which recovers traffic that would otherwise bounce.

How Do You Fix a Broken .htaccess File?

If your site broke immediately after saving this file, the file is almost certainly the cause. Restore your backup first, then work out which directive failed.

What Should You Do if Your .htaccess File Was Hacked?

Malicious redirects and injected rewrite rules are a common symptom of a compromised site, and attackers favor this file because visitors get redirected before any application code runs. Cleaning Up a .htaccess Hack covers removing the injected rules. Treat the cleanup as one step: if the file was modified, something else on the account was likely modified too, so scan for the entry point before you consider it resolved.

When Should These Rules Move Out of .htaccess?

Apache reads .htaccess on every request and checks parent directories along the way, so heavy rule sets add measurable overhead under load. Apache’s own documentation recommends placing directives in the main server configuration whenever you have access to it (Apache HTTP Server documentation). That access requires root, which comes with VPS Hosting and Dedicated Servers, not shared plans.

For most sites the difference is small. It becomes worth acting on when you are running dozens of rewrite rules, serving high concurrency traffic, or seeing time to first byte climb without an obvious application cause.

Where to Get Help With .htaccess Rules

Editing this file is well within reach for most site owners, and the guides above cover the common cases. If a rule is not behaving as expected, or your site is down and you cannot identify which directive caused it, our support team is available 24/7 and can review the file with you. Contact us and we will take a look.

Summarize and Research with AI
Share on Social Media

Leave a Reply