.htaccess Redirect Generator
Generate redirect rules for Apache .htaccess: force HTTPS, pick www or non-www, move pages or a whole domain. The matching Nginx config is shown alongside.
What do you want to redirect?
Generated rules
.htaccess, at the top of the file
Nginx server blocks
On CloudPanel, add the page rules to the site's Vhost editor inside the main server block. CloudPanel already handles HTTPS and www redirects when you set them in the site settings.
Before you add these rules
- Make sure HTTPS works on every address first. Redirecting to an address without a valid certificate shows visitors a security warning.
- Back up your current
.htaccess. A typo can take the whole site down with a 500 error. - Put the rules above any existing ones, including those added by WordPress or other software.
- Test in a private window, then check the result with the Redirect Checker.
Common problems
- Too many redirects. Usually an HTTPS rule here combined with a CDN or proxy set to connect to your server over HTTP, such as Cloudflare's Flexible SSL mode. The rules here check the
X-Forwarded-Protoheader to avoid that, but setting Cloudflare to Full (strict) is the real fix. - Nothing happens. The host may not allow
.htaccessoverrides, ormod_rewriteis not enabled. Ask your host, or use the Nginx version if your server runs Nginx. - Browser keeps the old redirect. Browsers cache 301 redirects. Test with a private window or a different browser while you are changing rules.
Limitations
- Old paths are matched exactly, with or without a trailing slash. For patterns, such as moving a whole folder, edit the generated rule or write a
RewriteRulewith a regular expression. - Query strings are passed through unchanged. Redirects based on query strings need extra
RewriteCondlines.