Editing and handling the .htaccess file
Why modify the .htaccess file?
The .htaccess file lets you control how Apache serves your WordPress site�redirects, permalinks, security rules, caching headers, and more. Modifying it can unlock powerful configuration options, but a small mistake can render your site inaccessible. This guide shows how to safely edit .htaccess using common hosting tools.
What is the .htaccess file?
.htaccess is a plain-text configuration file placed in a site�s directory (often the �root� or public_html folder). Apache reads it on every request and applies the directives it contains. In a WordPress environment, it typically handles �pretty� permalinks and may include security or performance rules.
Before you edit
- Make a backup
Always download a copy of the existing�.htaccess�file before making changes. If anything goes wrong, you can restore the original and avoid downtime. - Use a code-friendly editor
Edit with a plain-text editor (e.g., Sublime Text, VS Code, Notepad). Avoid word processors like Microsoft Word or Google Docs, which can insert hidden formatting. - Check file visibility
By default,�.htaccess�is hidden. Ensure your FTP client or control panel is set to�show hidden files. - Test immediately
After saving changes, load your site in a browser. If you see a �500 Internal Server Error,� revert to the backup and inspect for syntax errors.
Where is the .htaccess file?
- In most setups, it lives in the�root�directory (the same location as�
wp-config.php). - If WordPress is installed in a subdirectory (e.g.,�
/blog), look there. - If no�
.htaccess�exists, WordPress will generate one when you save your permalink settings�then you can download and edit that new file.
How to edit .htaccess via FTP/SFTP
- Obtain credentials
� Hostname, username, password (and port for SFTP).
� If in doubt, request them from your hosting provider. - Connect with an FTP/SFTP client
� Recommended:�FileZilla�or any SFTP-capable client.
� Enter credentials and connect. - Show hidden files
� In FileZilla: go to�Server ? Force showing hidden files.
� In other clients: check preferences for �show dotfiles.� - Locate the file
� Navigate to your site�s root (often�public_html,�www, or the folder named after your domain).
� Right-click�.htaccess�and select�Download. - Edit and upload
� Open the downloaded file in your editor.
� Make the desired changes, save, then drag the updated file back to the server�confirming �Overwrite.�
How to edit .htaccess via cPanel
- Log in�to your hosting account and open�cPanel.
- Select�File Manager.
- In File Manager, click�Settings�(top right) and enable�Show Hidden Files (dotfiles).
- Navigate to your site�s root folder (e.g.,�
public_html). - Right-click�
.htaccess�and choose�Download�(or�Edit�for in-line editing). - If downloaded, edit locally and then use�Upload�to replace the file. If editing in-line, make changes and click�Save Changes.
How to edit .htaccess via Plesk
- Log in�to Plesk and go to�Websites & Domains.
- Click�File Manager�for your domain.
- Click the�gear icon�or�Settings, then enable�Show Hidden Files.
- Locate the�
.htaccess�file in the domain�s root directory. - Select it and choose�Download�or�Edit in Text Editor.
- After editing locally, upload the revised file; if in-editor, save directly.
How to edit .htaccess via DirectAdmin
- Log in�to DirectAdmin and click�File Manager.
- Click�Options�(top right) and tick�Show Hidden Files.
- Open the folder for your website (e.g.,�
public_html). - Locate�
.htaccess�and use�Download�to edit locally or�Edit�for in-browser changes. - Upload the edited file or save changes in the editor.
Things to know about editing the .htaccess file
- Syntax matters
Missing a single character (e.g., a space, slash, or�<�bracket) can cause a �500 Internal Server Error.� - Order of directives
Apache processes rules top-to-bottom. Place redirects before WordPress�s own rewrite block if you want them to run first. - Backup plugin
Leverage a reliable backup solution (for example, Solid Backups � NextGen) to create a backup before making changes. - File permissions
After uploading, ensure�.htaccess�retains a permission of�644�(owner read/write; group/world read). - Testing environment
Whenever possible, make changes in a staging site to catch errors before affecting live users.
Be sure to preserve this section of the .htaccess 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
as it is needed for WordPress to function correctly.