Hostwinds Tutorials

Search results for:

Table of Contents

How To Create And Edit An .htaccess File
Linux Shell (Command Prompt)

Creating and Editing an .htaccess File

Tags: htaccess 

How To Create And Edit An .htaccess File
Linux Shell (Command Prompt)

Since you're reading this article, you may need to create or edit a .htaccess file. However, you may also be wondering what a .htaccess file is. A .htaccess file is a configuration file specifically to be used in tandem with the Apache webserver. It can allow you to customize things such as how a file or folder is served up or limiting access to specific files or folders. This article will go over how to create and edit a .htaccess file from cPanel and through the Linux shell (command prompt). Let's get started!

How To Create And Edit An .htaccess File


To create a .htaccess file through cPanel, you'll first need to be logged in to cPanel. Once logged in, please refer to the following steps.

  1. Click on the File Manager icon located under the files section.
  1. Select the location of where you'd like to create this file, such as public_html
  2. Click the New File icon.
  1. Name the file .htaccess
  2. Click Create New File
  1. If you cannot view this file once you have created it, you'll need to enable Show Hidden Files.
  1. Locate and right-click the file from the list
  2. Select the Edit or Code Edit option from the pop-up menu
  1. Click edit
  2. You should now be in the editor, which should open in a separate tab
  3. Once you're satisfied with any changes you have made, press the Save Changes button
  1. Once the changes have been saved, you may close the editor

Linux Shell (Command Prompt)

You must first be logged into the server via SSH. If you're not certain how to access your server via SSH, please refer to the following article, which covers this: Connecting to Your Server via SSH.

  1. Navigate to where you'd like the .htaccess to be created
    1. This can be in various places; however, the syntax is cd /path/to/folder
  2. Use a text editor of your choice to create and edit the file simultaneously
    1. Nano – nano .htaccess
    2. Vi – vi .htaccess
    3. Vim – vim .htaccess

To save the file in Nano press, CTRL+O  then Enter and finally CTRL+X.

In Vim, you'd press the Esc key followed by the colon (:) key and then type wq! in the terminal.

Written by Michael Brower  /  June 22, 2017