U.UtilityApp
📈 SEOFree · No signup

.htaccess Redirect Generator

Turn a list of old → new paths into ready-to-paste Apache 301 redirect rules.

One line in, one Redirect line out

Each line you type is an old path, a space and the new destination. The generator turns it into an Apache Redirect 301 directive, a permanent redirect. The starting list gives:

Redirect 301 /old-page /new-page Redirect 301 /blog/old-post /blog/new-post

The old path must start with a slash and must not include your domain. The destination can be a path on the same site, as above, or a full address on another domain, such as https://newsite.com/pricing.

Lines with only one item are dropped, and anything after the second item is ignored. Both happen silently, so compare the number of output lines with the number of pages you are moving.

A redirect also moves everything below the old path

A Redirect line matches the old path and everything underneath it, and carries the rest of the address across. Redirect 301 /blog /news sends /blog to /news, and also /blog/spring-sale to /news/spring-sale.

That is handy when you rename a whole section, but it affects the order of your lines. Apache uses the first Redirect that matches, so a specific line has to come before a broader one:

Redirect 301 /blog/spring-sale /offers Redirect 301 /blog /news

With those two lines swapped, /blog/spring-sale would match /blog first and end up at /news/spring-sale.

What this kind of redirect can't do

Redirect lines are simple by design. For these jobs you need RewriteRule lines from Apache's mod_rewrite instead:

  • Matching a query string. An old address like /product.php?id=42 can't be matched on its ?id=42 part.
  • Patterns. Sending every .html page to the same address without the extension needs a regular expression.
  • Moving the whole site from http to https, or from www to the bare domain.

Paths with spaces are another limit. The generator splits each line at spaces, so /old page /new becomes a redirect from /old to page. Add quotation marks around such a path by hand after copying, or better, avoid spaces in URLs.

.htaccess files are read by Apache and servers built to be compatible with it. Nginx ignores them, so on Nginx the redirects go in the server configuration instead.

Test before you rely on it

Browsers remember permanent redirects. If you test a line, notice a typo and fix it, your browser may keep sending you to the wrong place. Test in a private window, or check from the command line with curl -I https://yoursite.com/old-page and look for 301 and the right Location in the reply.

Also check for chains. If /a redirects to /b and an older line already sends /b to /c, point /a straight at /c. Then update your own internal links to the new addresses, so visitors and crawlers stop going through the redirect at all.

Frequently asked questions

Should I use a 301 or a 302 redirect?+

Use 301 when the move is permanent, which is what this generator writes. For a temporary move, such as a page down for maintenance, change 301 to 302 in the copied lines so search engines keep the original address.

Where does the .htaccess file go?+

In the folder your site is served from, usually the one with your home page. If a .htaccess file is already there, for example the one WordPress writes for its permalinks, add the new lines to it instead of replacing it.

Does the generator check that the new pages exist?+

No. It only formats the text you type. A typo in a destination produces a valid-looking line that sends visitors to a missing page, so open every destination address once before you upload the file.

Embed this tool on your website

Free to use on blogs, school sites and intranets. Paste this code into your page's HTML; please keep the credit line.

<iframe src="https://utilityapp.lat/embed/seo/htaccess-redirect-generator" title=".htaccess Redirect Generator" width="100%" height="600" style="border:0;max-width:760px" loading="lazy"></iframe>
<p style="font-size:13px"><a href="https://utilityapp.lat/seo/htaccess-redirect-generator">.htaccess Redirect Generator</a> by UtilityApp</p>