Skip to content

.htaccess Redirect Generator

This .htaccess redirect generator turns a list of old and new URLs into redirect rules you can paste straight into your .htaccess file or Nginx config.

Lets you paste full URLs and makes every target a full https address, so each redirect is one hop.

Separate the two with a space, a tab or a comma, so two columns pasted from a spreadsheet work as they are. Lines starting with # are skipped. Nothing you type leaves your browser.

Site-wide rules (optional)

Note

Everything runs in your browser. Back up your current .htaccess before you paste rules into it, and test a few old URLs as soon as it is live: a typing mistake in .htaccess can take the whole site down with a 500 error.

It writes exact matches, so redirecting /old does not also catch /old-news, follows any chains inside your list so every old URL reaches its final page in one hop, leaves out loops and duplicates and says why, and switches to mod_rewrite when an old URL has a query string, which a plain Redirect cannot see. It can add the http to https and www rules too, in the right order. Everything runs in your browser; nothing is sent anywhere.

Use this tool often? Bookmark this page, so it is one click away next time.

Email me this result

Want a copy for your records or a client? Leave your email and we'll send you this result. It is written by a real person at Crawl Cove, not an automated blast, so it may take a little while to arrive. We'll only use your address to send it, unless you also tick the box below. Privacy policy.

That email address doesn't look right. Please check it and try again.

Something went wrong saving your address. Your result above is unaffected; please try again.

Got it. We'll email your result to you. Nothing else lands in your inbox unless you ticked the tips box.

How to create 301 redirects in .htaccess

  1. Add your site address

    Optional, but it lets you paste full URLs and makes every target a full https address on your preferred host, so each redirect is a single hop.

  2. Paste the old and new URLs

    One pair a line, separated by a space, a tab or a comma. Two columns copied from a spreadsheet work as they are, header row and all.

  3. Choose the type and server

    301 for a permanent move, 302 or 307 for a temporary one. Pick Apache for .htaccess or Nginx for a server block, and tick the site-wide rules you need.

  4. Copy, upload, then test

    Back up your current .htaccess, add the rules near the top, and open a few old URLs in the redirect checker to see each one land in one hop with the status you chose.

What the generator writes

For Apache it writes RedirectMatch rules anchored at both ends, such as RedirectMatch 301 ^/old-page/?$ https://www.example.com/new-page, so each rule matches one address and, with the trailing slash option on, its slash variant. When any old URL has a query string, or you add the https or www rules, it writes every rule with mod_rewrite instead, so the two modules never compete over the same request. For Nginx it writes one exact location block per old path with a return line, and a separate server block for the site-wide move. Download .htaccess saves the Apache rules as a file.

Redirect chains and loops

Why plain Redirect catches more than you meant

Apache's Redirect directive matches by prefix. Redirect 301 /blog /news sends /blog to /news, and also /blog/boiler-pressure to /news/boiler-pressure, which is right for moving a whole folder and wrong for moving one page. It also never looks at the query string, so Redirect 301 /page?id=12 /new matches nothing at all. That is why this generator uses RedirectMatch with an anchored pattern for single pages, and RewriteRule with a RewriteCond on %{QUERY_STRING} when the old address has parameters.

Redirect chains and loops in your list

Migration spreadsheets grow over time, and a page that moved once often moves again: /old-page to /new-page in 2024, then /new-page to /final-page this year. Two rules in a row make a chain, and every extra hop costs time and, for search engines, one more request before they reach the page. The generator follows each target through the rest of your list and points the old URL straight at the final address. Two rules that point at each other would loop forever, so they are left out and named, along with any URL redirected twice, where the first rule would win.

http to https and www in the same file

Site-wide rules belong after the page rules. If they run first, an old http://example.com/old-page goes to https://www.example.com/old-page and only then to the new page: two hops. With your site address filled in, every page rule already targets the final https address on your preferred host, and the site-wide rule catches everything else in one hop. If the site sits behind Cloudflare or another proxy that terminates HTTPS, %{HTTPS} can read off on every request and loop, so test %{HTTP:X-Forwarded-Proto} instead.

check HTTP headers

301, 302, 307 or 308?

Use 301 when a page has moved for good; it is the code search engines treat as a permanent move and the one to use in a migration. 308 is also permanent and keeps the request method, which matters for forms and APIs rather than pages. 302 and 307 are temporary: use them for a page that will come back, such as a seasonal offer, because a search engine may keep the old URL indexed. A temporary redirect left in place for months is a common audit finding.

Before you upload

Save a copy of the .htaccess file you have now. Put the rules near the top, after RewriteEngine On if the file already has it (it only needs to appear once) and before any WordPress or CMS block. A syntax error in .htaccess returns a 500 error for every page, so open the home page and a couple of old URLs straight after uploading, and restore the backup if anything breaks. The rules use QSD to drop the old query string, which needs Apache 2.4 or later.

Frequently asked questions

Is this .htaccess redirect generator free?
Yes. It is free, needs no sign-up, and runs entirely in your browser, so the URLs you paste are never sent anywhere.
How do I redirect one page to another in .htaccess?
Add a line such as RedirectMatch 301 ^/old-page/?$ https://www.example.com/new-page to the .htaccess file in your site's root folder. Paste the two URLs above and the generator writes it for you, exact match included.
What is the difference between Redirect and RewriteRule?
Redirect (mod_alias) is simple and matches by path prefix. RewriteRule (mod_rewrite) matches a regular expression and can test conditions such as the query string, the host or HTTPS. Mixing the two in one file can give surprising results, so the generator uses one or the other for the whole set.
Can I redirect a URL with a query string?
Yes, but not with Redirect or RedirectMatch, which never see the query string. The generator writes a RewriteCond on %{QUERY_STRING} followed by a RewriteRule, and drops the old parameters from the target.
How many redirects can I put in .htaccess?
There is no fixed limit, but Apache reads the file on every request, so thousands of rules slow the site down. For a large migration, put the rules in the server configuration or use a pattern that covers a whole folder.
Does it work for Nginx?
Yes. Choose Nginx and it writes location blocks with return lines for the page redirects, and a server block for the https and www move. Nginx has no .htaccess, so the rules go in your server configuration and need a reload.
How do I check the redirects work?
Once the rules are live, open an old URL in the redirect checker on this site. It shows each hop with its status code, so you can confirm a 301 that lands on the final page in one step.
Can I find every redirect chain on my site?
Not here: this tool writes rules from your list. Crawl Cove, the desktop crawler, follows every link on a site and lists each redirect chain, loop and redirect that ends on an error, and it has a permanent Free plan.

From one page to your whole site

This writes the rules. Crawl Cove checks what they do across the whole site: every redirect chain, loop and redirect that ends on an error, and every page that still links to an old address. See test a redirect or check redirects site-wide.

Download free