Skip to content
Tezmy Tools

.htaccess Redirect Generator

Write 301 redirect rules for Apache .htaccess or nginx

Redirect type

Server

Some browsers save the file as htaccess.txt. Rename it to .htaccess after downloading.

Before you use them

  • Back up your current .htaccess first.
  • Test on a copy of the site before you use it live.
  • Apache needs mod_rewrite enabled for the rewrite rules.
  • Put redirect rules above WordPress or other rules.

Redirect chains and loops are not checked. This tool doesn't change any file on your server.

Runs in your browser. Nothing is uploaded.

About the .htaccess Redirect Generator

.htaccess Redirect Generator writes the redirect rules you would otherwise have to remember. Pick what you need: send one page to another, redirect a whole list of old addresses, force HTTPS, choose between www and non-www, add or remove a trailing slash, or move a whole domain to a new one. Choose 301, 302, 307 or 308, and switch between Apache .htaccess and nginx. The rules appear only when every input is valid, and line breaks are rejected so nothing extra can slip into a rule. The tool doesn't touch your server. It gives you text to copy, and you should test it on a copy of your site first.

Updated September 2026

How to use the .htaccess Redirect Generator

  1. 1Choose what you need, such as One page to another or HTTP to HTTPS.
  2. 2Fill in the fields and pick the redirect type, then choose Apache or nginx.
  3. 3Copy the rules or download them as .htaccess or redirects.conf.
  4. 4Back up your current file, paste the rules in and test the redirects.

301, 302, 307 and 308 redirects

A redirect tells a browser or search engine that a page now lives somewhere else. Use 301 when the move is permanent, for example after you rename a page or change domain. Use 302 for a temporary move, such as sending visitors to a holding page during maintenance. The 308 code is a permanent redirect that keeps the request method, and 307 is its temporary twin.

Choosing the right one matters for search: a permanent redirect asks search engines to update their listing, while a temporary one asks them to keep the old address.

Where the rules go

On Apache, rules go in a file called .htaccess in the site's root folder. Put redirect rules near the top, above rules from WordPress or other software, because Apache reads them in order and a rule that ends processing can stop yours from being reached. For nginx, the rules belong in a server configuration file, and the server must be reloaded before they take effect.

Back up your current file before you change it, and test on a copy of the site first.

HTTPS, www and trailing slashes

  • HTTP to HTTPS: sends every insecure request to the secure version of the same address.
  • www to non-www, or the other way: keeps one version of your address so pages aren't duplicated.
  • Add trailing slash: makes /page redirect to /page/, skipping files.
  • Remove trailing slash: makes /page/ redirect to /page, skipping folders.
  • Move a whole domain: sends every address on the old domain to the new one, keeping the page path if you choose.

Testing your redirects

After you upload the rules, open the old address in a private window and confirm it lands where you expect. Check that it does not bounce between two addresses, which is called a redirect loop, and that a chain of several redirects has not built up, because each extra step slows the visitor. This tool does not check for chains or loops.

Hosting setups differ: WordPress plugins, CDNs and proxies can handle redirects before the server does, and some hosts turn .htaccess off. For crawl rules rather than redirects, see Robots.txt Generator, and for tracking links see UTM Builder. Check links with the URL Encoder & Decoder, and write page tags with the Meta Tag Generator.

Features

  • Eight kinds of redirect in one tool
  • Apache .htaccess and nginx output
  • Bulk list of up to 1,000 pairs with clear line-by-line errors
  • 301, 302, 307 and 308 codes
  • Domain move with or without the page path
  • Rules only appear when the input is valid

Frequently asked questions

How do I create a 301 redirect in .htaccess?

Choose One page to another, type the old path such as /old-page and the new address, keep the type on 301 and copy the result. For Apache it is one line: Redirect 301 /old-page https://example.com/new-page. Paste it into your .htaccess file.

What is the difference between 301 and 302?

A 301 says a page has moved permanently, so search engines pass their attention to the new address and browsers may remember it. A 302 says the move is temporary. The 307 and 308 codes are similar to 302 and 301 but insist that the request method is not changed.

How do I redirect HTTP to HTTPS?

Choose HTTP to HTTPS. For Apache it produces mod_rewrite lines that send any request that isn't secure to the same address with https. For nginx it produces a server block that listens on port 80 and returns 301 to the secure address.

How do I redirect www to non-www?

Choose www to non-www, enter your domain without www, and copy the rules. To go the other way, choose non-www to www. Pick one version of your address and redirect the other to it, so search engines see a single site.

How do I redirect many old URLs at once?

Choose Many pages and type one pair per line, with the old path first and the new address second, separated by a space or a comma. Lines that start with # are treated as comments. If a line is wrong, the error names the line number.

Why is my redirect not working?

Common causes are a missing mod_rewrite module, .htaccess being switched off by your host, rules placed below other rules that stop processing, a plugin or CDN handling the request first, or the browser showing a cached result. Test in a private window and check that the old path is exactly as typed.

Does Apache Redirect match the whole path?

Apache's Redirect matches by path prefix, so /old also matches /old/child and sends it to the new address plus the rest of the path. Nginx location = matches only the exact path.

Related tools