Choose what your .htaccess should do: force HTTPS, add or remove www, redirect old pages, protect files and speed up the site. You get correct lines with a comment for each part.
Start building the fileFour steps, all in your browser with no sign-up.
HTTPS, www, protection and caching.
Old path then new, one per line.
With a comment for each part.
After a backup, before the WordPress block.
A small configuration file in your site folder that the server reads before serving any page. It controls redirects, protection and caching without touching server settings. It works on Apache and LiteSpeed servers, as used by cPanel hosting, and not on Nginx.
| Section | What it does |
|---|---|
| HTTPS | Sends every http visit to https with a permanent 301, so pages are not duplicated in Google. |
| www | Keeps the site on one address form. |
| Redirect 301 | Moves an old page to a new one and keeps its search strength. |
| File protection | Stops wp-config.php and config files being opened from a browser. |
| Compression and caching | Shrinks pages and keeps images in the visitor's browser so the next visit is faster. |
.htaccess first.# BEGIN WordPress if present, and do not edit between BEGIN and END because WordPress rewrites it.After forcing HTTPS, confirm the certificate with the SSL checker. Behind Cloudflare, set encryption to Full to avoid a redirect loop.
Step-by-step fixes from our knowledge base.
Short definitions of what you meet along the way.
Did not find your answer? Ask us on WhatsApp
It works on Apache and LiteSpeed servers, including cPanel hosting. Nginx servers do not read htaccess and need server configuration instead.
Usually a line the server does not support. Remove what you added or restore the old copy, then add sections one by one to find the cause.
This usually happens with Cloudflare set to Flexible. Change it to Full, or remove the HTTPS section and let Cloudflare redirect.
Yes, write the path in Arabic and save the file as UTF-8. Use the Arabic URL tool to switch link forms.
Yes for most sites, and it reduces brute-force attacks. It does stop the WordPress mobile app and some plugins such as Jetpack.
Above "# BEGIN WordPress", so WordPress does not remove them when permalinks are saved.
Restore the file from your backup at once, then add lines part by part to find the culprit.
LiteSpeed servers and a free, auto-renewing SSL certificate.
We use necessary cookies to run the site, and Google Analytics to measure visits only if you agree. You can change your choice at any time from “Cookie settings”. Privacy policy