Saturday, October 24, 2026The WordPress PlaygroundFacebookXPinterest
Glossary

.htaccess

Have you ever wondered how WordPress turns a link like ?p=123 into a clean address like /my-first-post/? On many servers, a tiny file called .htaccess does that work behind the scenes.

The .htaccess file (short for hypertext access) is a configuration file for the Apache web server. Its rules apply to the folder it sits in and every folder below it.

What does .htaccess do in WordPress?

WordPress uses it mainly for pretty permalinks. When you save your settings at Settings → Permalinks, WordPress writes a few rewrite rules into the file. These rules send any request that is not a real file or folder to index.php. WordPress then works out which post or page to show.

Site owners also use it for plenty of other jobs:

  • Redirecting old URLs to new ones
  • Forcing HTTPS on every page
  • Blocking bad bots or IP addresses
  • Setting browser caching rules

Where to find the .htaccess file

It lives in the root folder of your site, next to wp-config.php. Since the name starts with a dot, it is a hidden file, so turn on the option to show hidden files in your FTP client or file manager. Our guide on how to access the .htaccess file in WordPress shows each method.

Keep in mind that .htaccess works only on Apache and LiteSpeed servers. If your host runs Nginx, the file is ignored.

How to add your own rules

WordPress keeps its rules between the # BEGIN WordPress and # END WordPress lines and rewrites that block whenever it refreshes them. So, always add your custom code outside those lines. For example, this rule stops anyone from opening wp-config.php in a browser:

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

A single typo can cause a 500 Internal Server Error, so download a copy before every edit. If something looks wrong, compare your file with the default WordPress .htaccess file.

Tip

If your posts suddenly show 404 errors, open Settings → Permalinks and click Save Changes without changing anything. WordPress rewrites its rules, and the problem is often gone.

That's it. The .htaccess file is small, but it controls a lot. If you have any questions, drop them in the comment section below.