The .htaccess file is a powerful per-directory configuration file that controls how Apache handles requests to your website. It can manage redirects, rewrite URLs, block access, and set PHP settings.
Where is the .htaccess File?
Your main .htaccess is in public_html/.htaccess. It is a hidden file β in File Manager, enable Show Hidden Files from the settings menu to see it.
Common .htaccess Rules
# Enable HTTPS redirect\nRewriteEngine On\nRewriteCond %{HTTPS} off\nRewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]\n\n# Set PHP memory limit\nphp_value memory_limit 256M\n\n# Block a specific IP\nDeny from 1.2.3.4\n\n# Prevent directory listing\nOptions -Indexes\n\n# Custom error pages\nErrorDocument 404 /404.html .htaccess and WordPress
WordPress adds its own rules to .htaccess for pretty permalinks:
# BEGIN WordPress\n<IfModule mod_rewrite.c>\nRewriteEngine On\nRewriteBase /\nRewriteRule ^index\.php$ - [L]\nRewriteCond %{REQUEST_FILENAME} !-f\nRewriteCond %{REQUEST_FILENAME} !-d\nRewriteRule . /index.php [L]\n</IfModule>\n# END WordPressDo not modify rules within the # BEGIN WordPress / # END WordPress block β WordPress manages these automatically.
Troubleshooting .htaccess Errors
A syntax error in .htaccess causes a 500 Internal Server Error. To fix it: rename the file to .htaccess_backup to temporarily disable it, then correct the error and rename it back. Always keep a backup before making changes.