The htaccess file: basics with examples
.htaccess is a small text file that changes how your web server treats a folder. Our servers run LiteSpeed, which reads the same rules as Apache, so the usual recipes, including every one below, work.
Edit it safely
- Open Account → Hosting → your site → Files. Hidden files show automatically.
- Open
public_htmland click.htaccess. It opens in the code editor. - If the editor has no History button, keep a copy first. Press Ctrl A (⌘ A on a Mac), copy the text, and paste it into a text file on your computer.
- Change one thing at a time, then press Ctrl S (⌘ S on a Mac) or click Save.
- Check the change in the review that appears, and click Save. When the editor has History, it keeps the version you replaced there.
- Load your site. If you see a 500 error, click History and restore the previous version, or paste your copy back over the file's text and save.
If the file changed on the server while you were editing, for example because a plugin rewrote it, the editor shows both versions and asks which to keep. It never overwrites the newer file without asking.
Rules apply to the folder they live in and everything below it. WordPress and other apps write their own blocks between # BEGIN and # END markers. Leave those alone and add your rules above or below them.
Recipes
# Force HTTPS
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# 301 redirect one page
Redirect 301 /old-page https://example.ca/new-page
# Custom error pages
ErrorDocument 404 /errors/404.html
ErrorDocument 500 /errors/500.html
# Browser caching: keep static files for a month
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType image/webp "access plus 1 month"
ExpiresByType text/css "access plus 1 month"
ExpiresByType application/javascript "access plus 1 month"
</IfModule>
# Block one IP and one range
<RequireAll>
Require all granted
Require not ip 203.0.113.45
Require not ip 198.51.100.0/24
</RequireAll>
# Stop folder listings
Options -Indexes
# Protect the .htaccess file and wp-config.php
<FilesMatch "^(\.htaccess|wp-config\.php)$">
Require all denied
</FilesMatch>
# Raise PHP limits for this folder
php_value upload_max_filesize 64M
php_value post_max_size 64M
For PHP settings, use Performance → Choose PHP for each site instead. It writes its own marked block at the top of .htaccess and checks the site still loads. Editing php_value lines yourself is an advanced alternative. A mistyped line causes a 500 error, and the page locks any setting it finds set that way. See Change PHP settings.
Related recipes
If something goes wrong
| Symptom | Fix |
|---|---|
| 500 Internal Server Error | Typo or unsupported directive. Restore the previous version from History, or from your copy, then read the error log |
| Rule seems ignored | An earlier rule ends with [L], or a cache is serving the old page |
| File isn't visible | Check you are in the right folder. Hidden files show in Files, but .htaccess lives where the site lives |
Still stuck? Ask us and we'll walk you through it.