Menu

.htaccess Redirect Generator

Purpose: Generate Apache 301 redirect rules from a list of old-path | new-url pairs - preserve SEO when moving pages.


  

Htaccess Redirect Generator: How It Works

A redirect tells browsers and search engines that a URL has moved. Getting the type and the ordering right preserves the ranking value a page has accumulated; getting it wrong loses that value or creates loops that take a site offline.

Choosing the status code

CodeMeaningUse for
301Moved permanentlyAlmost all SEO redirects — passes ranking signals
302Found (temporary)Genuinely temporary moves, A/B tests, maintenance
307Temporary, method preservedTemporary redirects that must not change POST to GET
308Permanent, method preservedPermanent moves on API endpoints
410GoneContent deliberately removed with no replacement

The common error is using 302 for a permanent move. Search engines treat a temporary redirect as a signal to keep the original URL indexed, so ranking value stays stranded on a URL that no longer serves content.

The rules that make Apache configuration work

RewriteEngine On

# Force HTTPS
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]

# Force www
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]

# Single page move
Redirect 301 /old-page /new-page

# Whole directory
RewriteRule ^old-section/(.*)$ /new-section/$1 [R=301,L]

Chains and loops

A chain is A → B → C. Each hop adds latency and search engines may stop following after several. Always redirect directly to the final destination and update the earlier rules when a target moves again.

A loop is A → B → A, which produces a 'too many redirects' error and takes the page completely offline. The usual cause is two rules — commonly an HTTPS rule and a www rule — written without conditions that exclude the state each other produces.

Redirect to the equivalent page

A redirect passes value only when the destination is genuinely a replacement. Mass-redirecting hundreds of deleted pages to the homepage is treated as a soft 404: the value does not transfer, and the user experience is poor. If there is no equivalent page, returning 410 is more honest and gets the URL removed cleanly.

Site migration checklist

  1. Map every old URL to its closest new equivalent before launch.
  2. Implement 301s for the whole map, not just top pages.
  3. Update internal links to point at the new URLs directly, not through redirects.
  4. Update the sitemap and resubmit it.
  5. Keep the old sitemap available briefly so old URLs are recrawled and the redirects discovered.
  6. Retain the redirects indefinitely — external links keep arriving for years.

Performance

Rules in .htaccess are read on every request, so hundreds of them measurably slow a site. Where you have server configuration access, moving rules into the main virtual host config is significantly faster. For very large redirect maps, a database or map-file lookup outperforms a long list of individual rules.

Frequently Asked Questions

Does a 301 redirect pass full ranking value?
Google has stated that PageRank is not diluted through 301 redirects. In practice a well-matched permanent redirect preserves most of a page's value, provided the destination is genuinely equivalent content.
301 or 302 — which should I use?
301 for anything permanent, which covers almost all SEO cases. 302 tells search engines to keep indexing the original URL, so using it for a permanent move strands your ranking value on a dead URL.
Why am I getting a redirect loop?
Usually two rules undoing each other — commonly an HTTPS rule and a www rule without conditions excluding the state the other creates. Add RewriteCond guards so each rule only fires when its condition is genuinely unmet.
Can I redirect everything to my homepage?
You can, but you should not. Google treats mass redirects to an unrelated homepage as soft 404s, so no value transfers. Redirect to an equivalent page, or return 410 where none exists.
How long should I keep redirects?
Indefinitely. External links and bookmarks pointing at old URLs continue to arrive for years. Removing a redirect converts every one of those into a 404.
Do redirects slow down my site?
Each hop adds a round trip, and .htaccess rules are evaluated on every request. A handful is negligible; hundreds are measurable. Redirect directly to the final URL and, where possible, move rules into the server configuration.

Related SEO Tools

Browse all SEO tools →