SMThe SERP MasterAdvanced SEO Tools

.htaccess 301 Redirect Generator

Turn a list of old-path/new-path pairs into real Apache .htaccess redirect rules, plus optional HTTPS and www normalization.

# Rules will appear here

Put these lines near the top of your site's .htaccess file, above any WordPress or other rewrite block. Only works on Apache (or servers running mod_rewrite) — Nginx uses a different syntax entirely.

Writing 301 Redirects in .htaccess

Paste your redirects one per line — the old path, a space, then the new URL — and choose whether to force HTTPS and add or remove www. The generator writes the host and protocol rules first, followed by a Redirect 301 line for each pair, ready to paste into your .htaccess file.

A 301 tells browsers and search engines that a page has moved permanently. Google passes the old URL's ranking signals to the new one, which is why redirects are the most important part of any URL change or site migration.

How to Use This Tool

  1. List your redirects

    One pair per line: /old-page https://example.com/new-page. The old side is a path starting with a slash; the new side can be a path or a full URL.

  2. Choose host rules

    Tick Force HTTPS, and choose whether to add www, remove it, or leave the host alone.

  3. Copy the output

    Paste it near the top of the .htaccess file in your site's root folder, before any CMS-generated block.

  4. Test every redirect

    Run a few old URLs through the Redirect Checker to confirm each lands in one hop on the right page.

What the Generated Rules Do

  • RewriteEngine On — switches on mod_rewrite, which the HTTPS and www rules need.
  • Force HTTPS — any request that arrives over plain HTTP is sent to the same URL on HTTPS with a 301.
  • Add www — requests to example.com go to www.example.com.
  • Remove www — requests to www.example.com go to example.com.
  • Redirect 301 /old /new — one line per pair, handled by mod_alias, sending the old path to the new URL permanently.

Redirect vs RewriteRule

Redirect 301 (mod_alias) is simpler and ideal for a flat list of one-to-one path changes, which is what this generator produces. RewriteRule (mod_rewrite) is more powerful — it handles patterns, wildcards, captured groups and conditions such as the host name — but it is overkill for a list of old and new pages.

Apache's documentation advises care when mixing the two in one file, because they run as separate modules. The combination generated here is common and works on typical hosts, but always test the result rather than assuming.

Gotchas That Catch People Out

  • Redirect matches by prefix. Redirect 301 /blog /news also sends /blog/any-post to /news/any-post. List more specific paths first, or use RedirectMatch or RewriteRule for exact matches.
  • Query strings are not part of the match. /page?id=5 cannot be targeted with a plain Redirect line; that needs a RewriteCond on the query string.
  • Paths with spaces or special characters must be encoded or quoted, or the line will not parse.
  • HTTPS and www rules can stack into two hops — http://example.com to https://example.com to https://www.example.com. Check with the Redirect Checker and combine them into one rule if you see a chain.
  • Browsers cache 301s hard. Test in a private window, because a redirect you have already removed can keep firing in your normal browser.

301 vs 302 Redirects

Use 301 when a page has moved for good: a new URL structure, a merged article, a domain change. Use 302 (or 307) when the move is temporary and the old URL will come back, such as during maintenance or a short promotion.

Google treats a long-standing 302 much like a 301 eventually, but the intent is clearer if you use the right code from the start. This generator writes 301s, since permanent moves are what people need .htaccess redirects for most often.

Redirects During a Site Migration

Map every old URL that has traffic or backlinks to its closest new equivalent — not all of them to the homepage, which Google treats much like a missing page. Export the old URLs from your sitemap, analytics and Search Console before the move so none are forgotten.

After launch, update internal links to point straight at the new URLs rather than relying on redirects, and submit the new sitemap. The Broken Link Checker finds internal links still pointing at old addresses, and the Bulk URL Formatter cleans up a URL list before you turn it into redirect pairs.

Where to Put These Rules

  • In the .htaccess file in your site's root folder, near the top.
  • Before any CMS-generated rewrite block — WordPress writes its own block between # BEGIN WordPress and # END WordPress, and that block should stay last.
  • Test on a staging copy first. A typo in .htaccess returns a 500 error for the whole site until it is fixed.
  • Keep a backup of the working file before every edit.

Frequently Asked Questions

Does this work on Nginx?

No. Nginx does not read .htaccess files and uses its own syntax — return 301 or rewrite directives inside a server block. This generator is for Apache and servers that emulate it, such as LiteSpeed.

Why force HTTPS and www at the top?

Normalising the protocol and host first means every path rule below it only has to handle one form of the URL, rather than every combination of http, https, www and non-www.

How do I redirect an entire domain to a new one?

Use a RewriteRule on the old domain that sends every path to the same path on the new domain, for example RewriteRule ^(.*)$ https://newdomain.com/$1 [R=301,L]. Keeping the path means each old page lands on its equivalent rather than the new homepage.

Do 301 redirects lose SEO value?

Google has said that 301 redirects pass ranking signals to the new URL. What loses value is redirecting pages to unrelated destinations, long chains of redirects, or removing redirects too soon after a migration.

How long should I keep redirects in place?

At least a year, and indefinitely for URLs with backlinks. Removing a redirect turns every old link and bookmark into a 404.

My site shows a 500 error after adding the rules. What happened?

Apache could not parse the file. Restore your backup, then look for a typo, a path with an unescaped space, or a module such as mod_rewrite that is not enabled on your host.