htaccess Generator: HTTPS, Redirects and Protection

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 file
.htaccesshttp → https301 /old → /newwww → ∅

Generator

Choose what you need

Your .htaccess

How the tool works

Four steps, all in your browser with no sign-up.

Pick settings

HTTPS, www, protection and caching.

Add redirects

Old path then new, one per line.

Copy the file

With a comment for each part.

Add it safely

After a backup, before the WordPress block.

What is an htaccess file?

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.

SectionWhat it does
HTTPSSends every http visit to https with a permanent 301, so pages are not duplicated in Google.
wwwKeeps the site on one address form.
Redirect 301Moves an old page to a new one and keeps its search strength.
File protectionStops wp-config.php and config files being opened from a browser.
Compression and cachingShrinks pages and keeps images in the visitor's browser so the next visit is faster.

How to add it safely

  1. Open the cPanel file manager and show hidden files.
  2. Download a copy of your current .htaccess first.
  3. Put the new lines at the top, before # BEGIN WordPress if present, and do not edit between BEGIN and END because WordPress rewrites it.
  4. Open your site. If you see error 500, remove what you added or restore the copy, and check with Is my website down?

After forcing HTTPS, confirm the certificate with the SSL checker. Behind Cloudflare, set encryption to Full to avoid a redirect loop.

Key terms

Short definitions of what you meet along the way.

htaccess
A configuration file read by Apache and LiteSpeed in each folder, used for redirects, forcing HTTPS and blocking access to sensitive files.
301 redirect
A permanent redirect telling browsers and Google that a page has moved, so its search value moves with it.
302 redirect
A temporary redirect that does not pass search value; use it only for maintenance or tests.
mod_rewrite
The server module that runs URL rewrite rules in htaccess, enabled on cPanel hosting.

Frequently asked questions

Did not find your answer? Ask us on WhatsApp

Does it work on any host?

It works on Apache and LiteSpeed servers, including cPanel hosting. Nginx servers do not read htaccess and need server configuration instead.

I got error 500 after editing. What now?

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.

I get a redirect loop after forcing HTTPS.

This usually happens with Cloudflare set to Flexible. Change it to Full, or remove the HTTPS section and let Cloudflare redirect.

Can I write Arabic paths in redirects?

Yes, write the path in Arabic and save the file as UTF-8. Use the Arabic URL tool to switch link forms.

Is blocking xmlrpc.php safe?

Yes for most sites, and it reduces brute-force attacks. It does stop the WordPress mobile app and some plugins such as Jetpack.

Where do htaccess lines go in WordPress?

Above "# BEGIN WordPress", so WordPress does not remove them when permalinks are saved.

What if I get a 500 error after editing?

Restore the file from your backup at once, then add lines part by part to find the culprit.

Fast hosting with sensible defaults

LiteSpeed servers and a free, auto-renewing SSL certificate.

Contact us on WhatsApp