Search The Hostwinds Guides Knowledge Base

Creating and Editing an .htaccess File

Share:

Since you’re reading this article you may need to create or edit an .htaccess file, however you may also be wondering what an .htaccess file is. An .htaccess file is a configuration file specifically to be used in tandem with the Apache web server. 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. In this article we will go over how to create and edit an .htaccess file from cPanel and through the Linux shell (command prompt). Let’s get started!

 

How To Create And Edit An .htaccess File

cPanel

To create an .htaccess file through cPanel, you’ll first need to be logged into 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

 

Showing the New File icon in the cPanel File Manager

 

  1. Name the file .htaccess
  2. Click Create New File

 

Showing the New File Creation interface in the cPanel File Manager

 

  1. If you’re not able to view this file once you have created it you’ll need to enable Show Hidden Files

 

Showing how 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

 

Showing the Edit and Code Edit option in the cPanel File Manager

 

  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

 

Showing 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 a 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.

 

Helpful Related Articles


Share:

Leave a Reply

Your email address will not be published. Required fields are marked *