Skip to content
SocialTools

Redirect Rule Generator

Turn a list of old | new paths into 301 redirect rules for Apache .htaccess and Nginx in one pass.

2 redirects configured

Apache .htaccess (RewriteRule)
RewriteEngine On RewriteRule ^old-page/?$ /new-page [R=301,L] RewriteRule ^blog/old-post/?$ /blog/new-post [R=301,L]
Nginx (return 301)
# Add inside your server { } block location = /old-page { return 301 /new-page; } location = /blog/old-post { return 301 /blog/new-post; }

Runs in your browser. Nothing you enter is uploaded.

What it does

When pages move during a redesign, a slug change or a content cleanup, each old URL needs a permanent redirect. This generator takes pairs written as old | new, one per line, and outputs two copy-ready blocks: Apache mod_rewrite rules for .htaccess and Nginx location blocks for a server config.

It suits site owners and developers handling a batch of path changes on one domain. Old paths get a leading slash if missing, regex characters such as dots and parentheses are escaped, and the Apache rule matches the old path with or without a trailing slash. Every rule is a 301. There are no options for 302s, HTTPS or www redirects.

How to use it

  1. 1

    In Redirect pairs (one per line: old | new), type each redirect as /old-path | /new-path.

  2. 2

    Check the count line, for example "2 redirects configured". Lines missing either side are skipped.

  3. 3

    Click Copy Apache rules for .htaccess, or Copy Nginx rules for an Nginx server.

  4. 4

    Paste the Apache block into the .htaccess file in your site root, or the Nginx blocks inside your server { } block, then reload Nginx.

  5. 5

    Visit each old URL to confirm it returns a single 301 to the new path.

What you get

An Apache block that starts with RewriteEngine On and has one RewriteRule per pair with [R=301,L] flags, and an Nginx block with a location = /old { return 301 /new; } entry per pair.

When to use it

Renaming blog slugs
Map each old post path to its new slug so existing links and bookmarks land on the right page after a URL cleanup.
Merging thin pages
Point several retired pages at one consolidated guide by writing one line per old path with the same destination.
Mixed Apache and Nginx setups
Both formats come from the same list, so a staging server on Nginx and production on Apache get identical redirects.
Dropping .html extensions
Pairs like /about.html | /about produce a correctly escaped Apache pattern, so the dot matches only a literal dot.

Example

Input

/services.html | /services
/blog/old-post | /blog/new-post

Output

RewriteEngine On

RewriteRule ^services\.html/?$ /services [R=301,L]
RewriteRule ^blog/old-post/?$ /blog/new-post [R=301,L]

# Add inside your server { } block

location = /services.html {
    return 301 /services;
}

location = /blog/old-post {
    return 301 /blog/new-post;
}

The dot in services.html is escaped in the Apache pattern, while the Nginx exact match fires only for the path exactly as written.

Tips

  • Write the old side as a path. The new side can be a path or a full URL: a destination starting with http:// or https:// is kept as-is, and anything else gets a leading slash if it is missing.
  • RewriteRule patterns never see the query string, so a pair like /page?id=4 | /new will not fire in Apache. Those redirects need a RewriteCond on %{QUERY_STRING}.
  • Put the rules above any CMS block in .htaccess (such as WordPress's # BEGIN WordPress section), or the CMS handles the request first.
  • Point every old path straight at its final destination to avoid chains of redirects.

Questions

Can these rules redirect to a different domain?

Yes, per page. Enter the destination as a full URL, such as /pricing | https://new-site.com/pricing, and both the Apache and Nginx rules send visitors there unchanged. To move a whole domain at once, a single domain-level rule is simpler than one line per page.

What does /?$ at the end of each Apache rule do?

It makes the trailing slash optional and anchors the match at the end, so /old-page and /old-page/ both redirect, but /old-page-2 does not.

Does the Nginx version also catch the trailing slash?

No. location = is an exact match, so /blog/old-post/ is not covered. If both forms were ever linked, add a second pair for the slash version.

Where does the .htaccess code go on shared hosting?

In the .htaccess file in the folder your domain points to, usually public_html. It needs Apache with mod_rewrite enabled, which most shared hosts provide.