How to Create .htaccess Redirects
- Pick a preset or set your canonical domain, HTTPS and www preference.
- Add clean-up options such as removing .html or trailing slashes.
- List directory moves and individual pages, one per line: the old path or URL, a space, then the new one.
- Test a few URLs in the redirect tester to confirm each reaches its final address in one hop.
- Copy the rules into the .htaccess file in your site's root folder (back up the old file first), then test in a private browser window.
301 Permanent vs 302 Temporary Redirects: SEO Impact
A 301 redirect tells browsers and search engines that a page has moved permanently. Google transfers the old URL's ranking signals to the new one and eventually replaces it in the index, which is why 301s are the right choice for HTTPS migrations, domain changes, merged pages and renamed URLs. A 302 redirect means the move is temporary, so search engines keep the original URL indexed. Use it for short-term situations such as A/B tests, maintenance pages or seasonal promotions. Browsers cache 301s aggressively, so test with a 302 first if you're unsure, then switch to 301.
Common Redirect Scenarios
| Scenario | What the rules do |
|---|---|
| Force HTTPS | Sends every http:// request to the same URL on https:// |
| www ↔ non-www | Picks one hostname as canonical so you don't have duplicate versions of every page |
| HTTPS + non-www together | Combines both conditions so http://www.example.com goes straight to https://example.com in one hop |
| Domain migration | Redirects every URL on the old domain to the same path on the new domain |
| Directory move | Maps /news/anything to /blog/anything |
| Clean URLs | Redirects /page.html to /page and serves the .html file behind the scenes |
Best Practices for Apache RewriteEngine Rules
- Avoid redirect chains. Each hop adds delay and can dilute signals. The generator points page redirects straight at the final canonical URL.
- Put specific rules before general ones. Individual pages come first, then folders, then domain-wide rules.
- Use the [L] and [NE] flags so processing stops after a redirect and special characters aren't double-encoded.
- Behind Cloudflare or a load balancer? The server may see every request as HTTP, and a normal HTTPS rule creates an endless loop. Tick the proxy option to check the X-Forwarded-Proto header instead.
- Update internal links and your sitemap to use the new URLs directly; redirects are a safety net, not a replacement.
- Keep redirects in place for at least a year after a migration, ideally permanently.
Real-World Example
A small business moved from http://www.old-site.com to https://example.com and renamed its blog folder from /news/ to /blog/. The domain migration preset, one directory rule and a handful of page redirects produced a single .htaccess file. In the tester, http://www.old-site.com/news/summer-sale now goes directly to https://example.com/blog/summer-sale in one 301 hop, instead of the three-step chain the old rules caused, and the site kept its search rankings through the move.
Testing Your Redirects Safely
Before uploading new rules, download a copy of your current .htaccess so you can restore it within seconds if something goes wrong. A single typo can cause a "500 Internal Server Error" on every page. Upload the new file, then test in a private browser window, because browsers cache 301 redirects and may show you an old result. Check the main variations of your home page (http and https, with and without www), a few deep pages, an image and a CSS file. Online header checkers or curl -I show the exact status code and Location header for each hop. Finally, update your XML sitemap and internal links to use the final URLs, and watch the Pages report in Google Search Console over the following weeks.
Frequently Asked Questions
Where is the .htaccess file?
In your website's root folder, usually public_html or www, next to index.html. It's a hidden file, so enable "show hidden files" in your file manager or FTP client.
Why do I get "too many redirects"?
Usually two rules undo each other, or an HTTPS rule runs behind a proxy that talks to your server over HTTP. Tick the proxy option, or check that your host's dashboard doesn't have a conflicting redirect.
Does .htaccess work on Nginx?
No. Nginx ignores .htaccess files. Choose the Nginx output and add the rules to your server configuration.
How do I redirect a URL with a query string?
Enter the full old URL including ?id=12. The generator adds a QUERY_STRING condition and drops the old query from the new URL.
How many redirects can .htaccess handle?
Hundreds work fine. For many thousands, it's more efficient to use a RewriteMap in the server configuration or redirect in your application.