.htaccess Redirect Generator
Paste old and new URLs and get 301 rules for the top of .htaccess, with loops, chains and duplicates caught first.
Your details
Full URLs on this domain are treated as your own pages.
Paste this at the very top of .htaccess, above # BEGIN WordPress
- Rules written
- 6
- Chains
- 1
- Loops removed
- 0
- Duplicates removed
- 0
# Redirects: keep this block above # BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^shop/old-hoodie/?$ /product/classic-hoodie/ [R=301,L]
RewriteRule ^collections/sale/?$ /product-category/sale/ [R=301,L]
RewriteRule ^pages/about-us/?$ /about/ [R=301,L]
RewriteRule ^blog/news/spring-launch/?$ /blog/spring-launch/ [R=301,L]
RewriteRule ^product/classic-hoodie-v1/?$ /product/classic-hoodie/ [R=301,L]
RewriteCond %{QUERY_STRING} ^id=42$
RewriteRule ^index\.php/?$ /product/classic-hoodie/ [R=301,L,QSD]
</IfModule>
# End redirectsLine 5 was a chain of 2 redirects. It now goes straight to /product/classic-hoodie/.
WordPress rewrites every unknown URL to index.php, so rules below # BEGIN WordPress never run. Back up .htaccess first, and test a few old URLs afterwards. This only works on Apache or LiteSpeed servers, not Nginx.
How the rules are built
In .htaccess, RewriteRule matches the path without its leading slash, so /shop/old-hoodie/ becomes ^shop/old-hoodie/?$. The /? makes the trailing slash optional. Query strings need a separate RewriteCond %{QUERY_STRING} line, and the QSD flag drops the old query string from the redirect.
The sample list
- 6 pairs pasted
- 6 rules written
- /product/classic-hoodie-v1/ → /shop/old-hoodie/ → /product/classic-hoodie/
- Chain of 2, flattened
- /index.php?id=42
- RewriteCond plus QSD
Every old URL reaches its final page in one hop.
The mod_alias option writes RedirectMatch lines instead. It's simpler but can't match query strings. Plain Redirect isn't used because it also redirects everything below a path.
Adding the rules to WordPress
- 01
Back up .htaccess
Download it with your host's file manager or SFTP. It's in the same folder as
wp-config.php. - 02
Paste above # BEGIN WordPress
WordPress sends every unknown URL to
index.php, so rules below its block never run. Don't paste inside the BEGIN/END WordPress markers, which WordPress rewrites. - 03
Test old URLs
Open a few old URLs in a private window and check each lands on the right page in one redirect.
On Nginx hosting, .htaccess is ignored. Use a redirect plugin instead, such as Redirection with our Redirection CSV generator.
What the checks catch
- Loops: a URL that redirects to itself, or A → B → A. These are removed so the site doesn't break.
- Chains: A → B → C. With “Fix chains” on, A goes straight to C. Each extra hop slows shoppers down.
- Duplicates: the same old URL twice. Only the first rule would ever run.
Questions people ask
Where do I put redirects in a WordPress .htaccess file?
At the very top, above # BEGIN WordPress. Rules below WordPress's block never run.
301 or 302?
Use 301 (or 308) for pages that have moved for good. It tells search engines to transfer the old URL's rankings. Use 302 or 307 only for temporary moves.
Can I redirect URLs with query strings?
Yes, in mod_rewrite mode. The tool adds a RewriteCond for the query string and drops it from the destination.
Does this work on Nginx?
No. Nginx doesn't read .htaccess. Use a redirect plugin or your host's redirect settings.
How many redirects can .htaccess handle?
Apache reads the file on every request, so thousands of lines can slow a site. For large migrations, a plugin with a database table is often better.
Related tools
Last reviewed 30 September 2026.
Sources: Apache HTTP Server 2.4: mod_rewrite (RewriteRule) · Apache HTTP Server 2.4: RewriteRule flags · Apache HTTP Server 2.4: mod_alias (Redirect, RedirectMatch)
