SupperTools

Useful Online Tools & Utilities to Make Everyday Tasks Easier.

Htaccess Redirect Generator for 301 and 302 Apache Rules

Generate correct .htaccess redirect directives for Apache in seconds. Create 301 and 302 rules for moved pages without risking a broken configuration.

Enter the path you want to redirect from (e.g., /old-page)
Enter the destination path or full URL.
Redirects all HTTP traffic to secure HTTPS.

Generated .htaccess Code

Copy the generated code below into your .htaccess file.

Move a page on an Apache hosted website and every bookmark, search result and link pointing at the old address starts returning errors, unless a redirect sends that traffic to the new location. Redirects on Apache live in the .htaccess file as directives that are easy to get subtly wrong: one mistyped flag can break a whole site. This htaccess redirect generator writes the directive for you from the old and new addresses, so the syntax is handled and you can concentrate on choosing the right redirect.

Redirects Explained Without the Jargon

A redirect is an instruction the server gives a browser or search engine: this address has moved, go there instead. The two codes that matter are 301, which means the move is permanent, and 302, which means it is temporary. Permanence is a signal, not just a technicality. A 301 tells search engines to transfer the old page's standing to the new one and to update their index, while a 302 says keep the original address listed because the detour will end. Simple one to one moves use the Redirect directive from mod_alias, such as sending an old page path to a new URL. Pattern based moves, domain wide changes, forcing HTTPS, or settling on one of www versus non-www usually call for mod_rewrite rules with conditions, which is where hand writing gets risky and a generator earns its keep.

What the Generator Writes for You

Give the generator an old address and a destination and it produces the exact directive line your .htaccess file needs, with the status code you chose built in. That removes the two commonest sources of failure: misremembered syntax and flags in the wrong order. The output is plain text you can read before you trust it, paste into the file alongside your existing rules, and remove just as easily if plans change. Because the rules it writes are the standard Apache forms, they sit comfortably next to redirects you created by hand and behave the same way under Apache and Apache compatible servers.

How to Create a Redirect Rule

  1. Decide whether the move is permanent (use 301) or temporary (use 302).
  2. Enter the old path exactly as visitors used it, and the full new URL it should land on.
  3. Generate the redirect code and read it once to confirm the addresses are the ones you meant.
  4. Download a backup copy of your current .htaccess file before changing anything.
  5. Paste the generated directive into .htaccess, keeping specific page rules above any broad catch all rules.
  6. Save, then visit the old address in a browser to confirm it lands on the new page.

Habits That Keep Redirects Healthy

Send each old page to its closest equivalent, not automatically to the homepage. A visitor who wanted a specific product and lands on a generic front page has effectively hit a soft error, and search engines treat mass homepage redirects that way too. Avoid chains: if one address already redirects to a second, point the first directly at the final destination rather than letting visitors hop through intermediaries, because each hop wastes time and crawl effort. Keep old rules in place; they cost nothing and keep years of inbound links working. Be careful with broad rules that can match their own target, since a rule that redirects everything including its destination creates a loop, which browsers report as too many redirects. After pasting a rule, run the old address through our redirect checker to see the status code returned. Our general htaccess generator covers the file's other common jobs, and if the site ever migrates servers, the htaccess to Nginx converter translates these rules to the other platform.

It also pays to settle your canonical address forms at the same time, with or without www, and HTTPS everywhere, and to write those domain level rules once, above the individual page redirects. Deciding them first prevents the classic tangle where a page redirect and a domain redirect fight each other and send visitors through two hops, or worse, around a loop.

Frequently Asked Questions

Where does the .htaccess file live?

For site wide redirects it belongs in the website's root directory, often public_html or a similarly named folder, alongside your homepage file. Rules in a root .htaccess apply to that directory and everything below it. If no such file exists yet, you can create a plain text file with exactly that name, including the leading dot.

Can a bad redirect line break my whole site?

Yes. Apache reads .htaccess on every request, and a syntax error typically produces a 500 error for the entire site until the file is fixed. That is why the backup in the steps matters: if a change breaks something, restoring the previous file or deleting the new lines returns the site to normal within seconds.

Should I use 301 or 302 for a page I redesigned?

Use 301 if the old address is retired for good and the new page replaces it, because that passes the old page's search standing to its successor. Reserve 302 for genuinely temporary situations, such as sending a page to a holding page during maintenance, where you intend the original address to resume its role afterwards.

How long should I keep a redirect in place?

Effectively forever, or at least as long as anything anywhere might still link to the old address. Redirects cost the server almost nothing, and old links, bookmarks and printed material can surface years later. Removing a rule is what breaks those visits, not keeping it.

Is redirecting everything to the homepage good enough?

No. Visitors land somewhere irrelevant to what they wanted, and search engines read a page that vanishes into the homepage as a soft 404, so the old page's standing is wasted. Redirect each address to the closest matching page, and only use the homepage when no equivalent exists at all.

What is the difference between www and non-www redirects?

They are the same address to you but two different hostnames to a server, so without a rule both versions of your site can be reached and indexed separately. One domain level redirect that forces a single form keeps your pages, links and statistics gathered under one canonical address.

Why the HTACCESS Redirect Generator Earns Its Place

The htaccess redirect generator takes the syntax risk out of moving pages on Apache: choose 301 or 302, supply the old and new addresses, and paste a correct directive into a backed up file. Redirect each page to its true successor, test the result, and your old links keep working long after the move.

Related Tools