Working with .htaccess
The .htaccess file controls server behaviour for your website.
Finding .htaccess
- Open File Manager
- Navigate to
public_html
- Click Settings (top right)
- Tick Show Hidden Files (dotfiles)
- Click Save
- You should now see .htaccess
Editing .htaccess
- Right-click .htaccess
- Select Edit
- Make your changes
- Click Save Changes
Common .htaccess Uses
Redirect HTTP to HTTPS
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Redirect www to non-www
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
Custom Error Pages
ErrorDocument 404 /404.html
ErrorDocument 500 /500.html
If Your Site Breaks
- Rename .htaccess to .htaccess_backup
- Test if site works
- If yes, review your changes
- Fix and rename back
Always backup: Copy .htaccess contents before editing. Syntax errors can break your site.