How to Locate and Create the WordPress .htaccess File on cPanel and Others Panels
When you install WordPress on your hosting account, the software adds a list of directories to your web server. From wp-admin that stores administrative files to the wp-content directory where themes and plugins are kept – these keep your pages up and running. htaccess wordpress
Aside from the core directories, WordPress also comes with the .htaccess file. In short, it is a configuration file that controls how your server is running. We will give you details about this configuration file and information on how to locate it or create a new file entirely.
In particular, we’ll guide you through the process of locating your WordPress site’s .htaccess file in cPanel.
To locate and create the WordPress .htaccess file on cPanel, DirectAdmin, and Plesk hosting panels and set up rewrite rules in the .htaccess file, follow these steps:
1. cPanel: .htaccess
- Log into your cPanel account.
- In the cPanel dashboard, locate the “Files” section, and then click on “File Manager.”
- Navigate to the “public_html” directory. Inside this directory, you’ll typically find your WordPress installation. Click on the folder corresponding to your WordPress site (usually labeled as “wp”).
- Search for the .htaccess file within your WordPress folder.
- If you can’t locate the .htaccess file, you may need to enable the option to show hidden files. To do this, click the “Settings” button in the upper right corner of the File Manager, and then tick the “Show Hidden Files (dotfiles)” option.
- After enabling the option to show hidden files, the .htaccess file should become visible in the list of files within your WordPress folder.
- To edit the .htaccess file, click on the file, and then select the Edit button from the menu.
- Now that you’ve located and opened your .htaccess file, you can begin editing it. Add code snippets above or below the existing code to customize the functionality of your WordPress site.
Before making any changes, keep in mind:
- If you have multiple domains in your hosting plan, each domain may have its own .htaccess file in its respective “public_html” directory.
- Since the .htaccess file is a server configuration file, making errors in the code can lead to server errors.
- It’s highly recommended to create a backup of your .htaccess file before making any modifications. This way, you can restore your WordPress site to a stable state in case any errors occur.
Example of rewrite rules for WordPress, which typically handle permalinks:
Copy This .htaccess code and Paste inside file.
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
2. DirectAdmin: .htaccess
Locate .htaccess file:
- Log in to your DirectAdmin account.
- Navigate to the “File Manager” or “File Manager Advanced” option.
- Make sure you are in the root directory of your WordPress installation.
- Look for the .htaccess file. It may be hidden, so enable the option to show hidden files if necessary.
Create .htaccess file and add rewrite rules:
- If the .htaccess file doesn’t exist, you can create it:
- Click the “Create New File” button.
- Name the file “.htaccess.”
- Edit the file and add your rewrite rules using the mod_rewrite syntax.
3. Plesk: .htaccess
Locate .htaccess file:
- Log in to your Plesk control panel.
- Go to the “File Manager” or “Files” section.
- Navigate to the directory where your WordPress installation is located.
- Check for the .htaccess file. It may be hidden, so ensure that you’ve enabled the option to show hidden files.
Create .htaccess file and add rewrite rules:
- If there’s no .htaccess file, you can create one:
- Click the “Create” button or “New” option.
- Name the file “.htaccess.”
- Edit the file and add your rewrite rules using mod_rewrite syntax.
When creating or editing the .htaccess file, be careful, as incorrect rules can break your website. If you’re unsure about the rules you need to add, consult WordPress documentation or seek assistance from a developer experienced with WordPress and .htaccess configuration. Always make a backup of your .htaccess file before making changes to it to avoid any issues.