Toolsky

Free Online Tools & Utilities for Every Task.

HTACCESS Redirect Generator

Generate HTACCESS Redirects

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.

Pages move. Products get renamed, blogs get restructured, whole sites change domains — and every old address left behind becomes a broken link for visitors and a lost signal for search engines. On Apache servers, the fix lives in a small file called .htaccess, and its redirect rules follow a picky syntax where one wrong character can take a site offline. The HTACCESS Redirect Generator on ToolSky writes those rules for you: tell it the old address and the new one, and it produces the correct directive, ready to paste.

Redirects and the .htaccess File, Briefly

The .htaccess file is a configuration file that Apache reads from a website's directories — most importantly the document root, where it can control every page on the site. Among its many jobs, it is the standard place to declare redirects using the mod_alias module. The workhorse directive looks like this: Redirect 301 /old-page.html https://example.com/new-page. It says: when anyone requests the old path, send them permanently to the new address. The number is the HTTP status code, and choosing it deliberately matters — 301 means permanent (the move is forever; browsers and search engines should update their records and transfer ranking signals), while 302 means temporary (the old address remains the real one).

For pattern-based moves — a whole folder of posts, for instance — mod_alias offers RedirectMatch, which accepts a regular expression so one line can redirect hundreds of URLs. More complex logic belongs to mod_rewrite, but a large share of everyday redirect jobs are exactly what Redirect and RedirectMatch were built for.

What the Generator Writes for You

  • Single-page redirects: the Redirect directive for moving one URL to another, with the status code you choose.
  • Permanent or temporary moves: generate a 301 for lasting restructures or a 302 for short-term changes, without memorising which syntax goes with which.
  • Pattern redirects: RedirectMatch rules that move whole groups of pages — a renamed category, a retired blog path — in one line.
  • Clean, paste-ready code: correctly ordered arguments and absolute target URLs, formatted to drop into an existing .htaccess file without syntax slips.

How to Generate and Install a Redirect

  1. Write down the old path exactly as visitors and search engines know it, and the full new URL it should land on.
  2. Decide whether the move is permanent (301) or temporary (302) — when in doubt about a restructure, it is almost always permanent.
  3. Enter the details into the generator on this page and produce the directive.
  4. Back up your current .htaccess file before touching it — download a copy you can restore in seconds.
  5. Open the .htaccess file in your site's document root (create it there if none exists) and paste the new rule, keeping more specific rules above more general ones.
  6. Save, then visit the old address in a fresh or private browser window and confirm you land on the new page.
  7. Check a few other pages of the site as well, to make sure the new rule did not disturb anything else, and test the redirect with the Redirect Checker if you want the status code confirmed.

Two Redirects Written Out and Explained

First, the everyday case: a pricing page moved during a redesign. The rule Redirect 301 /pricing-old.html https://example.com/pricing permanently sends every request for the old file to the new page, and passes the move's authority along with it. Second, a structural case: a blog that lived under /blog/ now lives under /articles/. One pattern rule handles the entire archive: RedirectMatch 301 ^/blog/(.*)$ https://example.com/articles/$1. The ^ and $ anchor the pattern, (.*) captures everything after /blog/, and $1 reinserts that captured text into the target — so /blog/first-post becomes /articles/first-post automatically, for every post, forever.

These two patterns cover a large share of real-world needs: renamed pages, merged sites, domain migrations, and folder restructures. The Apache documentation for mod_alias is the authoritative reference for the directives (see the Apache mod_alias documentation). And if your hosting runs Nginx rather than Apache, .htaccess will be ignored entirely — that stack needs its own syntax, which the Htaccess to Nginx Converter translates for you.

Handle With Care: .htaccess Failure Modes

The file's power is its danger. A single malformed line can produce a server error across the whole site, which is why the backup in step four is not optional ceremony — it is your undo button, and restoring it takes less than a minute. Rule order is the subtler trap: Apache evaluates RedirectMatch patterns in order, so a broad pattern placed above a specific one will swallow requests the specific rule was meant to catch. Put the narrow rules first.

Avoid chaining your own redirects — old page to middle page to final page — because each hop slows the visitor and dilutes the signal; always point the oldest address straight at the final destination. Loops are the worst failure of all: if page A redirects to page B and anything sends B back to A, browsers give up with a "too many redirects" error, so after installing rules, click through the affected paths yourself. Finally, remember the file's scope: .htaccess works only on Apache servers with overrides permitted by the host; on a managed platform that forbids it, the same redirects belong in the platform's own redirect manager instead.

Frequently Asked Questions

Should I use a 301 or a 302 redirect?

Use 301 for any move you intend to keep — restructures, renames, domain changes — because it tells search engines to transfer indexing and ranking signals to the new URL. Use 302 only when the change is genuinely temporary and the old address will resume.

Where does the .htaccess file go?

In the directory it should govern — for site-wide redirects, your document root (the folder containing your homepage, often public_html). Rules there apply to that folder and everything beneath it.

My site broke right after I edited .htaccess. What now?

Restore the backup copy you made before editing. A syntax error in .htaccess commonly produces a 500 error site-wide; putting back the previous version returns the site instantly, and you can then re-add your rule and find the mistake calmly.

Can one rule redirect a whole folder of pages?

Yes — that is what RedirectMatch with a capture group does. The pattern matches the old folder path and reuses the remainder of each URL in the new location, moving every page in the folder with a single line.

Does .htaccess work on Nginx servers?

No. Nginx does not read .htaccess files at all; redirects there are written as rewrite rules in the server configuration. If you are migrating, your Apache rules need translating rather than copying.

How long does Google take to process a 301?

It depends on how often the old URL is crawled. Frequently visited pages are usually picked up within days; deep, rarely crawled pages can take weeks. The redirect works for visitors immediately regardless.

Can I redirect visitors from an old domain to a new one?

Yes, that is a common use — a rule matching the old domain's addresses and sending them to the equivalent pages on the new domain. Keep page-level mapping where possible rather than dumping every old URL onto the new homepage.

Old Addresses Keep Working — If You Tell Them Where to Go

Every link anyone has ever shared, bookmarked, or indexed is a small promise your site made. Redirect rules are how you keep those promises after the site changes shape. Generate them carefully, back up first, and test like a visitor — and no restructure ever has to mean starting from zero.