Htaccess Redirect Generator

Htaccess Redirect Generator

Build safe Apache redirect rules without learning the syntax

Select redirect type:

What the Htaccess Redirect Generator Does

On sites that run on the Apache web server, redirects are often written in a file called .htaccess. The rules use a compact syntax that is easy to get wrong, and a single typo can take a site offline. The Htaccess Redirect Generator on WebTOOLkt writes the rules for you. Choose the kind of redirect, enter the old and new addresses and copy the code into your file.

It helps site owners after a redesign, a domain change or a move to https, and developers who want a quick starting point they can check and adapt.

How to Use the Htaccess Redirect Generator

  1. Choose the type of redirect: a single page, a whole folder, www to non-www, non-www to www or http to https.
  2. Select the status code. Use 301 for permanent moves and 302 for temporary ones.
  3. Enter the old and new addresses.
  4. Generate the rules and read them carefully.
  5. Download a backup of your current .htaccess file from the server.
  6. Paste the new rules into the file, normally near the top, and save.
  7. Test the redirects immediately with the Redirect Checker.

Common Redirect Types

  • Page to page. Send an old URL to a new one with a 301 so visitors and search engines land in the right place.
  • Folder to folder. Move an entire section while keeping each page's path.
  • Domain to domain. Forward every URL from an old domain to its matching URL on a new one.
  • Force https. Redirect all http requests to the secure version of the site.
  • Choose www or non-www. Pick a single preferred hostname and redirect the other to it, so you do not split signals between two versions.
  • Trailing slash rules. Make URLs consistent, with or without a final slash.

How .htaccess Redirects Work

Apache reads the .htaccess file for each request and applies any rules it finds. Simple one-to-one moves can use the Redirect directive from the mod_alias module, described in the Apache mod_alias documentation. More flexible patterns use mod_rewrite, explained in the Apache rewrite guide. The general behaviour of the file is covered in the .htaccess how-to. Because many WordPress plugins also write to this file, put your rules above or outside the sections they manage and keep notes on what you change.

Important Warnings

  • Apache only. Servers running nginx, IIS and some other platforms do not read .htaccess files. Redirects there are set elsewhere.
  • Back up first. A syntax error usually produces a 500 error across the whole site. Keep a copy so you can restore it in seconds.
  • Beware of loops. A rule that sends a URL to itself, or two rules that send visitors back and forth, will break the page.
  • Mind rule order. Rules run from top to bottom, and the first matching rule may stop the rest.
  • Do not redirect everything to the homepage. Send each old page to the most relevant new page.
  • Hosting restrictions. Some hosts disable parts of .htaccess. Check with your provider if rules do not work.

Testing Your Redirects

  1. Open the old URL in a private browser window, which avoids cached redirects.
  2. Confirm it lands on the new URL.
  3. Run it through the Redirect Checker to confirm that there is only one hop and that the status code is correct.
  4. Check the final page with the HTTP Status Code Checker.
  5. Test both http and https, and both www and non-www versions.
  6. After a large migration, monitor errors in Google Search Console for several weeks.

Why Use This Tool Instead of Other Options

Copying snippets from forums can leave you with rules that do not fit your setup. The Htaccess Redirect Generator creates clean, readable rules from clear choices, free and without sign-up. It pairs with the Redirect Checker and the HTTP Status Code Checker on WebTOOLkt so you can create, verify and troubleshoot in one place.

Related WebTOOLkt Tools

Useful External Resources

Frequently Asked Questions

Where is the .htaccess file?

Usually in the root folder of your website. It may be hidden, so enable hidden files in your file manager.

Will a 301 redirect keep my rankings?

A correct permanent redirect to an equivalent page helps preserve signals, though results can vary.

My site shows a 500 error after editing. What now?

Restore your backup. Then re-add the rules one at a time to find the error.


Avatar

Syed M

Creator/Developer

Enjoy the little things in life. For one day, you may look back and realize they were the big things. Many of life's failures are people who did not realize how close they were to success when they gave up.

Cookie
We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it. Kindly Donate for a cause.