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
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.
- Click on the File Manager icon located under the files section
- Select the location of where you’d like to create this file such as public_html
- Click the New File icon
- Name the file .htaccess
- Click Create New File
- If you’re not able to view this file once you have created it you’ll need to enable Show Hidden Files
- Locate and right click the file from the list
- Select the Edit or Code Edit option from the pop up menu
- Click edit
- You should now be in the editor which should open in a separate tab
- Once you’re satisfied with any changes you have made press the Save Changes button
- 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
- Navigate to where you’d like the .htaccess to be created
- This can be in a various places however the syntax is cd /path/to/folder
- Use a text editor of your choice to create and edit the file simultaneously
- Nano – nano .htaccess
- Vi – vi .htaccess
- 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.