htaccess Redirect Generator – Free 301 Redirect Code for Apache and LiteSpeed
Paste your old and new URLs to get ready-to-use .htaccess redirect rules. Add HTTPS and www rules, or move a whole domain, without writing RewriteRules by hand.
Which Redirect Should You Use?
Redirects send visitors and Google from an old URL to a new one. The right type keeps your rankings safe.
| Situation | Use | Why |
|---|---|---|
| Page moved or URL changed | 301 | Passes rankings to the new URL |
| Deleted page with a close replacement | 301 to the replacement | Keeps visitors and links useful |
| Short sale or maintenance page | 302 | Google keeps the original URL indexed |
| Moved from http to https | Force HTTPS (301) | One secure version of every page |
| New domain name | Whole-domain 301 | Moves every page to the same path on the new domain |
Redirect Tips
Back up first
One typing mistake in .htaccess can take your whole site down. Keep a copy to restore.
Avoid chains
Redirect old URLs straight to the final URL, not through several steps.
Redirect to related pages
Sending every old page to the homepage can be treated like a "not found" page.
Update internal links
Change links on your own site to the new URL so they do not rely on redirects.
Clean new URLs
Make short, readable URLs with our URL slug generator.
Check robots.txt too
After a move, make sure the new site is not blocked. Build one with our robots.txt generator.
Learn Technical SEO Hands-On
Redirects protect your rankings when URLs change. Learn site migrations, Search Console and technical SEO with live websites in Coimbatore.
Frequently Asked Questions
Where do I put this code?
In the .htaccess file in your website's root folder. On WordPress, paste it above the "# BEGIN WordPress" line. Always back up the file first.
What is the difference between 301 and 302 redirects?
A 301 is permanent and passes rankings to the new URL. A 302 is temporary, so Google keeps the old URL in search.
Does this work on LiteSpeed hosting?
Yes. LiteSpeed reads Apache .htaccess rules. It does not work on Nginx servers, which use a different config format.
Can I redirect URLs with query strings?
Yes. If the old URL has ?something, the tool adds a condition for it and removes the query from the redirect.
Is there an easier way on WordPress?
Rank Math and other SEO plugins have a redirections manager where you can add redirects without editing files.
Is this htaccess redirect generator free?
Yes. It is free, needs no login, and works in your browser.
More Free Digital Marketing Tools
All free, no sign-up. See all tools
