Articles

What Is a .htaccess File?

A .htaccess file allows you to control the behavior of the Apache web server through safe and simple customizations.

With a .htaccess file, you can use common Apache modules, such as mod_rewrite.

A .htaccess file is a plain text file that sits in your app's public directory. Plain text comprises the basic characters free of distinguishing fonts, styles, or sizes; in other words, a plain text file is not a Microsoft Word document (.doc or .docx).

When you install them on your server, many apps already include a .htaccess file that you can edit to apply more rewrite rules when needed.

However, you can also create your own .htaccess file if your app doesn't include one.

Creating a .htaccess File

Because the dot (.) makes .htaccess a hidden file on most computer operating systems, the easiest way to create one is by using your SFTP client; we'll use Cyberduck in this tutorial.

First, SFTP in to your server. Open the public directory where you want the file to live and select an existing file within it.

Then, select New File from the Cyberduck File menu.

Name your new file .htaccess and click Create.

Now, double click this file, and it will open with your default text editor so you can enter the code needed to customize Apache's behavior.