.htaccess Redirect Generator

Updated October 2026

Generate Apache .htaccess redirect rules: exact-match RedirectMatch lines for normal URLs and mod_rewrite rules when the old URL has a query string. One URL or a whole list.

Advertisement

Advertisement

Input Mode

The URL path you want to redirect from (e.g., /old-page). Rules match this exact path; add a second redirect for the trailing-slash version if both exist.

The destination URL (can be relative path or full URL)

301 redirects preserve SEO link equity and are permanent

The .htaccess 301 Redirect Rule

For a normal URL the generator writes an anchored, exact-match rule:

RedirectMatch 301 ^/old-page$ https://www.example.com/new-page

The ^ and $ anchors mean only /old-page matches. The plain Redirect directive, by contrast, matches by prefix: it would also send /old-page/anything to /new-page/anything, and it loops when the new URL starts with the old one.

When the old URL has a query string

Redirect and RedirectMatch never see the query string. For an old URL such as /old.php?id=5 the generator switches to mod_rewrite:

RewriteEngine On
RewriteCond %{QUERY_STRING} ^id=5$
RewriteRule ^old\.php$ /products/five? [R=301,L,NE]

The trailing ? on the destination drops the old query string so it is not appended to the new URL.

Where to Put the Rules in .htaccess

Order matters. Apache applies mod_rewrite rules from top to bottom, and a framework block such as WordPress's sends every request to index.php. Put your redirects above that block:

# Your redirects first
RedirectMatch 301 ^/old-page$ https://www.example.com/new-page

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
...
</IfModule>
# END WordPress

Keep a copy of the file before editing. A syntax error in .htaccess produces a 500 error for the whole site until it is fixed.

Other Common .htaccess Redirects

# HTTP to HTTPS
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

# non-www to www
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^ https://www.example.com%{REQUEST_URI} [R=301,L]

# Move a whole directory, keeping the rest of the path
RedirectMatch 301 ^/blog/(.*)$ /articles/$1

Redirect Generators for Other Servers

The same tool is available preset for each server, plus a combined version:

After the redirects are live, confirm each old URL answers 301 and lands on a working page with the broken link checker, and submit a sitemap of the new URLs made with the XML sitemap generator.

How to Use

  1. 1

    Apache (.htaccess) is already selected as the server type

  2. 2

    Enter the old path and the new URL, or switch to Bulk Redirects for a list

  3. 3

    Choose 301 (permanent) or 302 (temporary)

  4. 4

    Copy the rules into the .htaccess file in your site root, above any existing WordPress or framework rules

  5. 5

    Save, then test the old URL in a private browser window

Why This Tool Matters for SEO

.htaccess is where most shared hosts and every WordPress site on Apache keep their redirects, and it is unforgiving: a prefix match that is too broad creates a redirect loop, and a rule placed below a framework rewrite never runs. Exact-match rules avoid both problems because each one matches a single URL and nothing else.

Frequently Asked Questions

What is the difference between Redirect, RedirectMatch and RewriteRule?

Redirect matches a URL prefix, so Redirect 301 /blog also redirects /blog/anything. RedirectMatch takes a regular expression and can be anchored to match one exact URL. RewriteRule, from mod_rewrite, is the only one that can test the query string, through a RewriteCond line. The generator uses anchored RedirectMatch for normal paths and RewriteRule when the old URL contains a query string.

Where does the .htaccess file go?

In the document root of the site, the same folder as your index file. It is a hidden file, so enable hidden files in your FTP client or file manager. If it does not exist, create a plain-text file named exactly .htaccess.

Why does my .htaccess redirect cause a loop?

The rule also matches the destination. This happens with prefix-matching Redirect lines such as Redirect 301 /shop /shop/new, where the new URL starts with the old one. Anchored exact-match rules, as generated here, do not have this problem.

Do .htaccess redirects work on Nginx or LiteSpeed?

LiteSpeed reads .htaccess and supports the same directives. Nginx ignores .htaccess completely; use the Nginx version of the rules instead.

Related Tools You Might Like

More in Technical SEO tools · All free SEO tools

Local Processing: Your data never leaves your browser