.htaccess redirect generator.
Generate Apache .htaccess code for the redirects most sites need: send old pages to new ones with 301 redirects, force HTTPS, settle on www or non-www, or move a whole site to a new domain. Rules are ordered to avoid redirect chains.
- Free, no sign-up
- Runs in your browser. Nothing you enter is sent to us.
.htaccess code
How to use the .htaccess Redirect Generator
- Enter your domain and choose HTTPS and www settings.
- List old and new addresses, one redirect per line: old path, a space, then the new path or URL.
- For a domain move, fill in the old domain instead.
- Back up your current .htaccess, paste the code at the top, then test with our redirect checker.
Before you edit .htaccess
.htaccess is a configuration file in your site's root folder (public_html on cPanel) that Apache reads on every request. A typo can take the whole site offline with a 500 error, so always download a copy first. If something breaks, put the old copy back. If your site runs on Nginx or a platform like Shopify or Wix, .htaccess doesn't apply: use their redirect settings instead.
What each section does
- Page redirects: send each old URL straight to its new address with a 301, which tells search engines the move is permanent.
- Force HTTPS: sends http:// visitors to the secure version. Works behind Cloudflare and most hosting proxies.
- www or non-www: picks one version of the domain so search engines don't see duplicates.
- Domain move: placed on the old domain, sends every page to the same path on the new one.
Avoiding redirect chains and loops
Page redirects are written first, pointing straight at the final https address, so a visitor never goes through two or three hops. The tool warns when a new address is itself redirected somewhere else. After uploading, test a few old URLs and all four versions of your domain with our redirect checker.
WordPress already has its own block in .htaccess (between "# BEGIN WordPress" and "# END WordPress"). Put these rules above it, and don't edit inside it. For a large migration, our website migration SEO service plans and tests every redirect.
About the .htaccess Redirect Generator.
Where is the .htaccess file?
In your website's root folder, usually public_html. It is a hidden file, so turn on "Show hidden files" in cPanel's File Manager.
What is a 301 redirect?
A permanent redirect. Browsers and search engines go to the new address, and search engines transfer the old page's rankings to it.
My site broke after editing .htaccess. What now?
Restore the copy you downloaded before editing. A 500 error almost always means a typo or a rule your server doesn't support.
Does this work on Nginx?
No. Nginx doesn't read .htaccess; redirects go in its server configuration instead.
Should I redirect deleted pages to the home page?
Only when nothing more relevant exists. Google treats mass redirects to the home page like missing pages. Point each one at its closest replacement.
You might also need these.
Redirect Checker
Trace every hop of a URL's redirects (301, 302, 307, 308), and check http, https and www all end in one place.
Use the toolURL Slug Generator
Turn page titles into clean, short, SEO-friendly URL slugs, one at a time or in bulk.
Use the toolRobots.txt Generator
Build a correct robots.txt, with WordPress presets and one-click control over AI crawlers.
Use the toolWant this done for you?
Free tools show you what to fix. We fix it, measure it, and keep it working while you run the business.