We don't just do content marketing. We build the tools that power it.

.htaccess Redirect Generator

This free tool helps you create .htaccess redirect rules for your Apache web server. You can generate 301 (permanent) or 302 (temporary) redirects for single URLs, bulk redirects, or even pattern-based redirects using regular expressions. Just enter your old and new URLs, pick your redirect type, and copy the generated code into your .htaccess file.

The URL path you want to redirect from.
The destination URL or path.

Generated .htaccess Code

0 Redirects
301 Type
0 Lines

What is an .htaccess File?

An .htaccess file is a configuration file used by Apache web servers. It sits in your website's root directory (or any subdirectory) and lets you control how the server handles requests without touching the main server config.

You can use .htaccess files to set up redirects, password protect directories, customize error pages, enable compression, and a lot more. The file name starts with a dot, which makes it a hidden file on Unix-based systems.

What's the Difference Between 301 and 302 Redirects?

The main difference comes down to permanence and how search engines treat them.

  • 301 (Permanent Redirect). This tells browsers and search engines that the page has moved permanently. Search engines will transfer most of the link equity (ranking power) to the new URL and update their index. Use this when you've permanently moved content to a new location.
  • 302 (Temporary Redirect). This signals that the move is temporary and the original URL might come back. Search engines keep the original URL in their index and don't pass as much link equity. Use this for A/B testing, maintenance pages, or when you plan to bring the old URL back.

If you're not sure which to use, go with 301. Most redirects in SEO and site migrations should be permanent.

Redirect vs RewriteRule - Which Should I Use?

Both accomplish redirects, but they work differently.

  • Redirect directive. Simple and straightforward. Great for basic URL-to-URL redirects. It only matches the URL path and doesn't support regex by default. Easy to read and less likely to cause issues.
  • RewriteRule. More powerful and flexible. Supports full regex patterns, can check conditions (like query strings or user agents), and works with captured groups for dynamic redirects. Use this when you need pattern matching or complex redirect logic.

For simple one-to-one redirects, the Redirect directive is usually enough. For anything involving patterns, wildcards, or conditions, you'll want RewriteRule.

How Do I Add This Code to My .htaccess File?

Here's how to add redirect rules to your .htaccess file.

  • Find your .htaccess file. It's usually in your website's root directory (where your index.php or index.html lives). If you can't see it, make sure your FTP client or file manager is set to show hidden files.
  • Make a backup. Before editing, download a copy of your current .htaccess file. This way you can restore it if something goes wrong.
  • Add the code. Paste the generated redirect rules at the top of your .htaccess file, before any existing rules. Order matters in .htaccess - rules are processed from top to bottom.
  • Save and test. Upload the file and test your redirects. If you get a 500 error, restore your backup and double-check the syntax.

If you're using WordPress, some plugins like Yoast or Redirection can manage redirects without touching .htaccess directly.

Common .htaccess Redirect Mistakes to Avoid

  • Creating redirect loops. This happens when URL A redirects to URL B, which redirects back to URL A. Always double-check your redirect chains.
  • Forgetting the leading slash. URLs in .htaccess redirects typically need to start with a forward slash for relative paths.
  • Using the wrong redirect type. Using 302 when you meant 301 can hurt your SEO since search engines won't transfer link equity properly.
  • Not escaping special characters. In regex patterns, characters like dots, question marks, and plus signs have special meanings. Escape them with a backslash if you want to match them literally.
  • Placing rules in the wrong order. More specific rules should come before general ones. A broad pattern at the top might catch URLs before more specific rules can process them.

Let's Grow Your Business

Want some free consulting? Let’s hop on a call and talk about what we can do to help.