
How to Configure WordPress .htaccess Rules Using cPanel File Manager
How to Configure WordPress .htaccess Rules Using cPanel File Manager
🧾 What is the .htaccess File?
The .htaccess
file is a hidden configuration file used by Apache web servers to control settings like redirects, security, permalinks, and more. In WordPress, it’s essential for SEO-friendly URLs and performance tweaks.
🔧 Step-by-Step: Edit .htaccess via cPanel
Step 1: Log into cPanel
- Visit
yourdomain.com/cpanel
- Enter your hosting username and password
Step 2: Open File Manager
- Scroll to the Files section
- Click on File Manager
- Navigate to
public_html
(or the root folder of your WordPress site)
Note: Make sure hidden files are visible by clicking Settings (top-right corner) and checking “Show Hidden Files (dotfiles)”.
Step 3: Locate or Create .htaccess
- Look for the file named
.htaccess
- If it doesn’t exist, click + File → Name it
.htaccess
Step 4: Edit the .htaccess File
- Right-click
.htaccess
→ Click Edit - Confirm any encoding prompts and begin editing
Always back up your
.htaccess
file before making changes.✅ Default WordPress .htaccess Rules
# 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
🛡 Useful Custom .htaccess Snippets
🔒 Block XML-RPC Attacks
<Files xmlrpc.php>
Order Deny,Allow
Deny from all
</Files>
🚀 Enable Browser Caching
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/gif "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType text/css "access plus 1 month"
ExpiresByType application/pdf "access plus 1 month"
ExpiresByType text/javascript "access plus 1 month"
ExpiresByType application/x-javascript "access plus 1 month"
</IfModule>
🔁 Redirect HTTP to HTTPS
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Use redirects carefully. A single mistake can break site access.
🧹 How to Reset .htaccess
- Delete current
.htaccess
(or rename to.htaccess.bak
) - Log in to your WordPress dashboard
- Go to Settings → Permalinks and click Save Changes
- This will regenerate the default
.htaccess
rules
✅ Final Thoughts
The .htaccess
file is a powerful tool for managing WordPress behavior, performance, and security. Always take backups and test after editing to avoid site crashes.