Skip to content
DA PA Checker

Free tool

.htaccess Redirect Generator

Create 301 redirects, force HTTPS and www rules for Apache and LiteSpeed.

Updated by the DA PA Checker team · How we measure

An .htaccess redirect generator writes ready rules for Apache and LiteSpeed web servers: 301 redirects for moved pages, a rule that forces HTTPS, and a rule that picks www or non www. Choose your options above, add old and new paths, and copy the code into your .htaccess file.

The .htaccess file is powerful and unforgiving. One typo can show every visitor a 500 error. A generator removes the typing mistakes, and the steps below remove the rest of the risk.

Key facts

  • .htaccess rules work on Apache and LiteSpeed servers, not on Nginx.
  • Custom rules go above the # BEGIN WordPress block.
  • Use 301 for permanent moves so signals pass to the new URL.
  • Cloudflare Flexible SSL plus a force HTTPS rule causes a redirect loop.
  • Keep redirects for at least a year after a move.

How to create redirect rules

  1. Pick whether the site should force HTTPS.
  2. Pick www or non www as your one main version.
  3. Add moved pages, one pair per line, as old path and new URL.
  4. Copy the generated code.
  5. Back up your current .htaccess file, paste the rules near the top and save.
  6. Test a few old URLs with the redirect checker.

What the rules look like

A rule that forces HTTPS on Apache or LiteSpeed:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

A single page that moved:

Redirect 301 /old-page/ https://example.com/new-page/

The generator combines these in the right order, so a visitor who types http://www.example.com/old-page/ gets one clean jump to the final address instead of three hops.

Where to paste the code in WordPress

Your .htaccess file sits in the main folder of your site, next to wp-config.php. Open it with your hosting file manager. Paste the new rules above the line that says # BEGIN WordPress. WordPress rewrites the part between BEGIN and END on its own, so anything you put inside that block can disappear when you save permalinks.

301 or 302?

CodeMeaningUse it when
301Moved permanentlyA page, a folder or a domain has moved for good
302Found, temporaryA page is away for a short time and will come back
307Temporary, keeps the methodRare on normal sites, used for forms and APIs
308Permanent, keeps the methodSame as 301 for most sites

For SEO, use 301 for anything permanent. Google passes the signals of the old URL to the new one, and the new URL replaces the old one in search results.

Common mistakes that cause errors or loops

  • A redirect loop with Cloudflare. If Cloudflare is set to Flexible SSL, your server sees every visit as http, so a force HTTPS rule redirects forever. Set Cloudflare SSL to Full, or use a condition on the X-Forwarded-Proto header.
  • Rules inside the WordPress block. They get deleted on the next permalink save.
  • Redirecting every old page to the home page. Google treats that like a 404. Point each old URL to the closest matching page.
  • Chains. Old URL to temporary URL to final URL wastes time. Point straight to the final address.

Keep a copy of the working .htaccess file on your computer. If a new rule breaks the site, upload the copy and the site is back in seconds.

What if my server runs Nginx?

Nginx does not read .htaccess files at all, so these rules will not do anything there. Ask your host to add the same redirects to the Nginx configuration, or use a redirect plugin such as the redirection module in Rank Math, which works on any server.

Moving a whole domain

When you move from an old domain to a new one, redirect every old URL to the same path on the new domain, not everything to the new home page. A single rule on the old site does this:

RewriteEngine On
RewriteRule ^(.*)$ https://newdomain.com/$1 [L,R=301]

Then add the new domain in Google Search Console and use the Change of Address tool from the old property. Keep the old domain registered and the redirects running for at least a year.

How to test your redirects

  1. Open each old URL in a private browser window. It should land on the new page.
  2. Run the old URL through the redirect checker. You want one 301 and then a 200.
  3. Try the http and www versions of your home page. All of them should end at your one main address.
  4. In Search Console, check the Pages report a week later for new 404 or redirect errors.

If the site shows a 500 error after saving, the last rule you added has a typo. Restore your backup, then add the rules back one at a time to find it.

Who uses this tool

Site owners use it when they change URLs, move to HTTPS or switch domains. Developers use it to write clean rules without hunting for syntax. SEO consultants use it during migrations to map old URLs to new ones. Anyone on LiteSpeed or Apache hosting, which includes most shared hosting, can paste the result directly.

Frequently asked questions

Can a wrong rule break my site?

Yes. A syntax error shows a 500 error on every page. Keep your backup open so you can restore it at once.

Do I need both the HTTPS and the www rule?

Use both if you want one single version of every URL, which is best for SEO. Pick one host, for example https://example.com, and send every other version there.

Does this work on LiteSpeed hosting like Hostinger?

Yes. LiteSpeed reads Apache style .htaccess rules.

How long until Google sees my 301?

Google finds it the next time it crawls the old URL. For important pages, request indexing of the new URL in Search Console to speed things up.

Should I keep redirects forever?

Keep them for at least a year, and longer if old links still point to the old URLs. They cost almost nothing to keep.