Emergency server help: get in touch

.htaccess Redirect Generator

Generate tested 301 redirect rules for Apache and LiteSpeed .htaccess, with the nginx equivalent: force HTTPS, www or non-www, move a whole domain, redirect a page or add trailing slashes.

Status
Live
Last updated
October 3, 2026

Choose a redirect type and the tool writes the rewrite rules for Apache and LiteSpeed (.htaccess on cPanel, DirectAdmin and most shared hosting) plus the equivalent nginx configuration. The rules avoid redirect loops behind Cloudflare and load balancers by also checking X-Forwarded-Proto.

Where to put the rules

Add the rules at the very top of the .htaccess file in the site’s document root, above the # BEGIN WordPress block, so they run before any application rewrite. LiteSpeed reads .htaccess the same way Apache does; after editing, LiteSpeed Enterprise picks up the change automatically.

Always test with curl -I http://example.com/ and curl -I https://www.example.com/ and confirm you get a single 301 to the final URL, not a chain of several redirects.

Avoiding redirect loops

If the site sits behind Cloudflare with SSL mode Flexible, the origin always sees HTTP and a plain HTTPS redirect loops forever. Set Cloudflare to Full (strict) with a valid origin certificate, or keep the X-Forwarded-Proto condition the generator adds.

Htaccess redirect generator at a glance

.htaccess Redirect Generator summary card: Choose a redirect type and the tool writes the rewrite rules for Apache and LiteSpeed (.htaccess on cPanel, DirectAdmin…
In short: Choose a redirect type and the tool writes the rewrite rules for Apache and LiteSpeed (.htaccess on cPanel, DirectAdmin and most shared hosting) plus the equivalent nginx configuration.
.htaccess Redirect Generator sections: Where to put the rules and Avoiding redirect loops
Covers: Where to put the rules and Avoiding redirect loops.
.htaccess Redirect Generator questions answered: 301 or 302? Does cPanel's Redirects page do the same thing?
Answers: 301 or 302? Does cPanel’s Redirects page do the same thing?

Official documentation: DirectAdmin documentation, cPanel & WHM documentation, Linux man pages.

Related guides: Fixing /scripts/upcp failures, tier blockers and “Upgrade blocked” on an unsupported OS · DirectAdmin removed legacy API endpoints in 2025–2026: what they were and their /api/ replacements · Broken custom Apache/nginx templates after the DOCROOT token change in DirectAdmin 1.710.

Frequently asked questions

301 or 302?

Use 301 for permanent moves so search engines transfer rankings. Use 302 only for temporary redirects such as maintenance pages.

Does cPanel’s Redirects page do the same thing?

Yes; cPanel writes similar rules into .htaccess. Writing them yourself gives you control over order and conditions.

How long should I keep a domain redirect?

At least a year, and ideally for as long as the old domain has links pointing to it.

Free website test

Is your website set up right?

Check SSL, security headers, redirects, robots.txt, sitemap, llms.txt and security.txt in one test. It takes about 30 seconds.