Websites change. Pages move, sections are reorganized, domains change, and old links keep circulating in search results, bookmarks, emails, and other sites. Without redirects, every visitor following an old link meets a dead end, and search engines gradually drop the old address without transferring its standing to the new one. The Htaccess Redirect Generator on FreeToolZones turns a simple list of old and new addresses into ready-to-paste Apache redirect rules, with your choice of redirect type and rule format.
This guide explains the five redirect types, the difference between the two rule formats, and how to write the input list so the generator produces correct rules. You will find step-by-step instructions, practical examples from site migrations and cleanup projects, and essential safety advice: back up your file, test one redirect first, and understand what each rule does before publishing it. Redirects are powerful, and this page helps you use them carefully.
What Is the Htaccess Redirect Generator?
The Htaccess Redirect Generator is a free online tool that creates redirect rules for Apache .htaccess files from a list of old-to-new URL pairs. The .htaccess file is a per-directory configuration file used by the Apache web server. Rules in it control how requests for addresses in that directory and below are handled, including sending visitors and search engines from an old address to a new one with an HTTP redirect status code.
You enter one redirect per line, in a simple form such as an old path, an arrow, and a new path. The tool accepts three separator styles: an arrow, a comma, or whitespace, and it ignores blank lines and comment lines starting with a hash. Each URL must start with a slash or with http or https. The tool validates every line and reports problems with line numbers, so a malformed entry does not silently produce a broken rule. The output is a block of rules ready to paste into your .htaccess file, preceded by a comment noting that the redirects were generated by FreeToolZones.
Two rule formats are offered. The Redirect directive format uses the simple mod_alias Redirect directive, one line per redirect, and suits straightforward one-to-one moves. The RewriteRule format uses mod_rewrite rules inside an IfModule block with the rewrite engine enabled, and offers more control, including an option to match the old path with or without a trailing slash. Five redirect types are available: 301 permanent, 302 temporary, 303 see other, 307 temporary preserving the request method, and 308 permanent preserving the request method. The result shows the redirect count, the chosen type, and the directive used, plus a reminder to test one redirect before adding the rest and to keep a backup of the original file.
- Simple input list: one redirect per line, with arrow, comma, or space separators.
- Line validation: malformed lines are reported with line numbers before any output is produced.
- Five redirect types: 301, 302, 303, 307, and 308, covering permanent and temporary moves.
- Two rule formats: simple Redirect directives or RewriteRule blocks with more control.
- Trailing slash option: RewriteRule patterns can match with or without a trailing slash.
- Copy and download: copy the rules or download them as a .htaccess file.
How to Use the Htaccess Redirect Generator
The widget has a large input box, two selectors, a trailing-slash checkbox, and four buttons. Follow these steps to generate redirect rules.
- Enter your redirects, one per line. Type or paste the list in the field labeled Redirects. Each line pairs an old URL with a new URL, for example an old page path, an arrow, and a new page path. You may use an arrow, a comma, or a space as the separator. Lines starting with a hash are treated as comments and ignored, and blank lines are skipped. Every URL must start with a slash or with http or https.
- Choose a redirect type. Use the Redirect type dropdown. Select 301 for a permanent move, which is the most common choice and the SEO-friendly option for pages that have moved for good. Select 302 for a temporary move. Select 303, 307, or 308 only when you understand their specific semantics for request methods and permanence, as described below.
- Choose a rule format. Use the Rule format dropdown. Select Redirect directive for simple, readable one-line rules using mod_alias. Select RewriteRule for mod_rewrite rules, which the tool wraps in an IfModule block with the rewrite engine enabled. RewriteRule format is the right choice when you need the trailing-slash option or when the rest of your .htaccess file already uses rewrite rules.
- Set the trailing-slash option for RewriteRule output. The checkbox labeled Match with or without a trailing slash applies only to RewriteRule output and is ticked by default. Leave it ticked so a rule for an old path also matches the same path with a trailing slash. Untick it when the old path must match exactly, without the slash variant. The option has no effect on Redirect directive output.
- Click Generate rules. Press the Generate rules button. If any line is malformed, the tool lists the errors with line numbers and produces no output, so you can fix the list and generate again. If the list is empty or contains only comments and blanks, the tool asks for at least one redirect. On success, the rules appear below with the redirect count, type, and directive, plus the backup and testing reminder.
- Copy or download the rules. Click Copy .htaccess rules to place the rules on your clipboard, or click Download .htaccess to save them as a file. If you try either before generating, the tool reminds you to generate first. Paste the rules into your .htaccess file carefully, keeping a backup of the original, and test one redirect before adding the rest. Click Clear to empty the input and output when you are done.
Do not paste the downloaded file over your existing .htaccess file without merging. The download contains only the generated rules. If your site already has a .htaccess file with other settings, add the new rules to it, preserving the existing content, and keep a backup copy of the original file before making any change.
Key Features of the Htaccess Redirect Generator
The generator handles the tedious and error-prone parts of writing redirect rules: consistent syntax, correct status codes, pattern escaping, and validation. The features below describe how each part works.
- Three input separators. Lines may use an arrow, a comma, or whitespace to separate the old and new URLs. The arrow form is the clearest for human review and is shown in the placeholder. The comma and space forms help when pasting from a spreadsheet or a plain list. The parser tries the arrow first, then the comma, then whitespace, and reports a line that matches none of the forms.
- Per-line validation with line numbers. Every line is checked: both URLs must be present, and both must start with a slash or with http or https. Failures are collected and reported together, each with its line number and a description of the problem. No partial output is produced when errors exist, so a typo in one line cannot hide among correct rules.
- Path extraction for old URLs. When the old URL is a full address including a domain, the tool strips the scheme and host and uses only the path for the rule, because both Redirect and RewriteRule match paths, not full URLs. A full old URL whose path is empty is treated as the site root. The new URL is kept exactly as entered, whether it is a path or a full address, because redirects may point to another domain.
- Redirect directive output. In Redirect format, each rule is one line naming the directive, the status code, the old path, and the new URL. A header comment identifies the block as generated. This format is easy to read and audit, and it requires only mod_alias, which is commonly enabled. Note that Redirect matches path prefixes, so a rule for a directory also affects addresses beneath it, which matters when ordering rules.
- RewriteRule output with escaping. In RewriteRule format, each rule anchors the old path pattern at the start and end, escapes special regex characters in the path, and adds the redirect code and last-rule flags. The block is wrapped in an IfModule check for mod_rewrite and enables the rewrite engine. Escaping ensures that dots, question marks, and other special characters in a path are matched literally rather than as pattern operators.
- Trailing-slash matching. When the trailing-slash option is enabled, the RewriteRule pattern for a path is adjusted so the trailing slash becomes optional, meaning both the bare path and the slashed path redirect. The root path is handled as a special case and is not given a redundant slash pattern. This option prevents the common failure where only one of the two URL forms redirects.
- Result statistics and safety reminder. The output statistics confirm the number of redirects, the status code, and the directive type, which helps you verify the generation settings at a glance. The reminder to test one redirect and keep a backup is part of every result, because a faulty .htaccess file can break a whole site, and a backup is the fastest recovery path.
Practical Use Cases for the Htaccess Redirect Generator
Redirects protect visitors, search visibility, and links whenever addresses change. The examples below cover the situations where a generated rule set saves the most time and prevents the most damage.
Site migration to new URLs
Redesigns and platform moves change URL structures: blog posts move to a news section, product pages gain new paths, and old category addresses disappear. A redirect list mapping each old address to its new counterpart preserves incoming links and search visibility. Generate the rules as 301 permanent redirects, test a sample across sections, and monitor for 404 errors after launch to catch addresses the list missed.
Domain change
When a site moves to a new domain, every old address should redirect to the corresponding new address. Enter full new URLs pointing to the new domain, generate the rules, and place them in the old domain .htaccess file. Permanent redirects tell search engines the move is lasting and help transfer ranking signals to the new domain over time. Keep the old domain and its redirects active for as long as old links remain in circulation.
Cleaning up deleted and merged pages
Pages are deleted, merged, or consolidated as content evolves. Each removed address that still receives traffic or links should redirect to the closest surviving equivalent, not to the home page, which frustrates visitors who expected specific content. Build the list from analytics and link data, generate the rules, and review each mapping for relevance before publishing.
Fixing trailing-slash and duplicate address issues
Many sites serve the same content at both the slashed and unslashed form of an address, creating duplicate content. Redirect rules can consolidate the variants to a single canonical form. The trailing-slash option in RewriteRule output helps match both forms during a move, while canonicalization rules for ongoing use should be designed carefully and tested to avoid redirect loops.
Temporary maintenance and campaign moves
A page may move temporarily during maintenance, a campaign, or a seasonal promotion. Temporary redirects, 302 or 307, tell search engines the move is not permanent and the original address should keep its standing. Use the temporary type deliberately, and replace it with a permanent redirect, or remove it, when the temporary period ends. Leaving temporary redirects in place indefinitely confuses both visitors and search engines.
Consolidating HTTP, www, and legacy variants
Legacy addresses with old prefixes, outdated sections, or retired campaign paths accumulate over years. A periodic cleanup maps each legacy address to its current equivalent and removes dead ends from the site. Generate the rules in batches by section, test each batch, and keep the list as documentation of what moved where and why.
Tips and Best Practices
- Back up before editing. Always save a copy of the current .htaccess file before adding rules. A single syntax error in the file can produce server errors across the site. With a backup, recovery is a one-step restore instead of a reconstruction from memory.
- Test one redirect first. Add a single rule, test it in a browser and with a fresh cache, and confirm the destination and status code. Then add the remaining rules. Testing incrementally isolates any faulty rule instead of presenting you with a batch of simultaneous failures.
- Choose permanent or temporary deliberately. Use 301 for moves that will not be reversed. Use 302 for genuinely temporary moves. Browsers and search engines cache 301 redirects aggressively, so a mistaken permanent redirect is hard to undo for visitors who already followed it. When unsure, start temporary and change to permanent once the move is confirmed.
- Avoid redirect chains and loops. A chain, where one address redirects to another that redirects again, slows visitors and dilutes search signals. A loop, where addresses redirect to each other, breaks access entirely. Map each old address directly to its final destination, and check the list for chains and cycles before generating.
- Order rules from specific to general. With Redirect directives, prefix matching means a general rule can capture addresses meant for a more specific rule. Place specific rules before general ones, and test overlapping addresses carefully. With RewriteRule output, the last-rule flag stops processing at the first match, so ordering matters there too.
- Keep the list as documentation. Save the input list alongside the generated rules, with dates and reasons for the moves. Future maintainers will thank you when they need to understand why an address redirects, and the list makes it easy to regenerate rules if the file is ever rebuilt.
- Verify on the live server. Rules that look correct can behave differently depending on server configuration, existing rules, and module availability. Always verify on the actual server, with the actual .htaccess file in place, rather than trusting the generated text alone. Confirm that mod_alias or mod_rewrite, whichever format you chose, is enabled.
Limitations of the Htaccess Redirect Generator
The tool generates rules; it does not apply them, test them against your server, or verify that the old and new addresses exist. It cannot detect redirect chains, loops, or conflicts with existing rules in your .htaccess file, because it sees only the list you enter. Generated rules target Apache servers using .htaccess files; they do not apply to Nginx, IIS, or other servers, which use different configuration formats, and they will have no effect if the server ignores .htaccess files or lacks the required module.
The generator handles exact path mappings only. It does not create pattern-based rules, query-string handling, conditional redirects based on device or referrer, or domain-wide wildcard redirects beyond what the listed pairs express. Query strings in old URLs are not matched by the generated path rules in the way a reader might expect, because Redirect and RewriteRule match paths, and query handling follows each directive own rules; test any address with a query string explicitly. The tool also does not check that new URLs return successful responses. Finally, the download contains only the generated rules, so merging with an existing .htaccess file is your responsibility, with a backup kept before any change.
Frequently Asked Questions
What is the difference between 301 and 302 redirects?
A 301 redirect means the move is permanent: the old address has moved for good, and search engines should transfer standing to the new address. A 302 redirect means the move is temporary: the old address should keep its standing because the content will return. Choose based on whether the move is lasting.
When should I use 303, 307, or 308?
These codes handle request methods specifically. A 303 tells the client to fetch the new address with a GET request, commonly after a form submission. A 307 is a temporary redirect that preserves the request method. A 308 is a permanent redirect that preserves the request method. Use them when method preservation matters, typically for API and form behavior, and use 301 or 302 for ordinary page moves.
Should I choose Redirect or RewriteRule format?
Choose Redirect for simple one-to-one moves when readability matters and no pattern control is needed. Choose RewriteRule when you need trailing-slash matching, when your file already uses rewrite rules, or when you need the extra control rewrite rules provide. Both formats produce working redirects when the required module is enabled.
What input formats does the generator accept?
One redirect per line, with the old and new URLs separated by an arrow, a comma, or whitespace. Blank lines are skipped, and lines starting with a hash are treated as comments. Both URLs must start with a slash or with http or https, and malformed lines are reported with line numbers.
Will the rules work on Nginx or other servers?
No. The generated rules are Apache .htaccess syntax. Nginx, IIS, and other servers use different configuration formats. If your site does not run on Apache with .htaccess support, translate the mappings into your server native redirect configuration instead.
What should I do if my site breaks after adding rules?
Restore the backup of the original .htaccess file immediately. Then add the rules back one at a time, testing after each, to identify the faulty rule. Check for syntax errors, conflicting rules, redirect loops, and missing modules. Never edit the live file without a backup.
Related Tools
These related tools encode URLs, generate codes for new addresses, and support site maintenance. Browse the full collection from the FreeToolZones home page.
- URL Encoder – encode URLs correctly before listing them as redirect targets.
- URL Decoder – decode and verify old URLs found in logs and reports.
- QR Code Generator – create QR codes pointing to new addresses after a move.
- Regex Tester – test patterns when planning pattern-based redirect rules.
- IP Address Lookup – check server and visitor addresses during migration troubleshooting.