Published: May 13, 2021 Updated: Jul 19, 2026

Htaccess URL Rewrite Free Tool


Enter a URL



Eg. http://www.example.com/test.php?firstid=1&secondid=10

About Htaccess URL Rewrite

What Htaccess URL Rewrite Does

This tool generates Apache .htaccess rewrite rules from plain inputs — you tell it what URL pattern you want to redirect or rewrite, and it outputs the correct mod_rewrite syntax you can paste into your site's .htaccess file. Instead of memorizing regular expression syntax, RewriteCond flags, and RewriteRule flag combinations, you describe the transformation you want (old path to new path, HTTP to HTTPS, www to non-www, removing a file extension, adding a trailing slash) and get back a rule block that's ready to drop into your configuration.

URL rewriting sits at the intersection of server administration and SEO. A wrong character in a regex, a missing [L] flag, or a rule placed in the wrong order can break an entire site or send visitors into a redirect loop. A generator that produces syntactically correct, properly ordered rules removes a whole category of mistakes that are easy to make by hand and painful to debug afterward.

Why .htaccess Rewriting Matters for SEO and Site Management

Search engines treat different URL forms of the same content — http://example.com, https://www.example.com, example.com/page, example.com/page/ — as separate pages unless you tell them otherwise. Every one of those variants can get crawled and indexed independently, splitting link equity and creating duplicate content signals. Server-level rewrites solve this once, at the source, rather than relying on canonical tags alone (which Google treats as a hint, not a directive).

Beyond canonicalization, rewrite rules are the backbone of:

  • Site migrations — mapping old URL structures to new ones after a redesign, CMS switch, or domain change, preserving accumulated link equity through 301 redirects.
  • Clean URLs — turning product.php?id=482 into /products/wireless-mouse/, which is both more readable to users and generally preferred in search results.
  • Protocol and host normalization — forcing HTTPS and a single canonical host (with or without www) so every inbound link and bookmark resolves to one authoritative URL.
  • Legacy content handling — redirecting discontinued pages to their closest living equivalent instead of serving 404s that waste crawl budget and frustrate users.
  • Access control and internal routing — blocking bad bots, restricting directories, or routing all requests through a front controller (common in frameworks like Laravel, WordPress, or Slim).

Get this wrong and you risk soft redirect chains, broken pagination, orphaned pages that never inherit their old rankings, or — worse — a misconfigured rule that 500-errors the entire site until someone finds the bad line.

How to Use the Htaccess URL Rewrite Tool

  1. Pick the rewrite type. Decide whether you need a redirect (the browser's address bar changes, status code 301 or 302) or an internal rewrite (the URL stays the same for the visitor, but Apache serves different content behind the scenes).
  2. Enter the source pattern. This is the URL or path structure you want to match — it can be a literal path (/old-page.html) or a pattern with placeholders for dynamic segments (/blog/{id}).
  3. Enter the target. Specify where matching requests should go — the new path, the HTTPS version of the same URL, or a query-string-based script.
  4. Choose the redirect type if applicable. Select 301 (permanent) for anything you intend to keep long-term, or 302 (temporary) for short-lived changes like A/B tests or maintenance redirects.
  5. Generate the rule. The tool outputs the RewriteCond and RewriteRule lines, correctly escaped and flagged.
  6. Copy the output into your .htaccess file, placed inside the correct block (after RewriteEngine On, and typically before any CMS-generated rewrite block such as WordPress's default rules).
  7. Test before you trust it. Load the old URL in an incognito window, check the HTTP status code with a header-inspection tool, and confirm the destination is correct and doesn't itself redirect again (redirect chains hurt both crawl efficiency and page load time).

Technical Background: How mod_rewrite Actually Works

Apache's mod_rewrite module processes .htaccess files top to bottom, per directory, on every request that hits a directory containing one. Two directives do the heavy lifting:

  • RewriteCond — a condition that must be true before the following RewriteRule applies. Common conditions check the host name, whether HTTPS is active, whether a file or directory physically exists, or match part of the query string.
  • RewriteRule — the actual pattern-to-target mapping, written as a regular expression matched against the requested path, followed by a substitution and a set of flags in square brackets.

The flags matter as much as the pattern itself. Leaving one off, or using the wrong one, is the single most common source of broken rewrite rules:

FlagMeaningTypical use
[L]Last — stop processing further rules if this one matchesAlmost every rule should end with this to prevent unintended chaining
[R=301]Redirect with HTTP 301 statusPermanent moves, canonical host/protocol enforcement
[R=302]Redirect with HTTP 302 statusTemporary redirects, maintenance pages, testing
[NC]No Case — match regardless of letter caseURLs that might be typed or linked with mixed casing
[QSA]Query String Append — preserves existing query parametersRewrites that shouldn't drop tracking or filter parameters
[NE]No Escape — prevents re-encoding of special characters in the targetTargets containing characters like % or & that shouldn't be re-escaped
[END]Stops all further rewrite processing, including in subsequent .htaccess files (Apache 2.4+)Definitive rules where no other rule should ever touch the request

An internal rewrite (no R flag) never changes what the visitor sees in the address bar — the server silently maps the request to a different resource. A redirect rule always sends the browser a new location and a status code, causing a visible URL change and a second request. Confusing the two is a frequent mistake: developers write internal rewrites when they actually needed SEO-visible 301s, or vice versa, which either hides the canonicalization from search engines or unnecessarily doubles HTTP round-trips for users.

Common Use Cases

Forcing HTTPS

Sites that still respond on plain HTTP send mixed signals to crawlers and browsers alike. A rewrite rule that checks %{HTTPS} off and redirects to the https:// version with a 301 consolidates all traffic — and all accumulated backlinks — onto the secure version.

WWW vs non-WWW normalization

Pick one canonical host and redirect the other to it. Leaving both live and reachable without a redirect means search engines may index both, diluting authority and occasionally displaying the "wrong" version in results.

Removing file extensions

Rewriting /about.php to serve at /about (or /about/) hides implementation details, looks cleaner in search snippets, and survives future backend rewrites (e.g., migrating from PHP to a different stack) without breaking existing URLs.

Legacy URL migration after a redesign

When a site restructures its URL hierarchy — moving from flat /page-name.html to nested /category/page-name/ — mapping every meaningful old URL to its new equivalent with 301s preserves search rankings that would otherwise be lost to 404s.

Query-string-to-path conversion

E-commerce and CMS platforms frequently generate URLs like index.php?page=contact. Rewriting these to /contact/ both improves readability and often correlates with better click-through rates in search results, since clean paths read more naturally than query strings.

Trailing slash consistency

Deciding once whether URLs end in a slash or not, and enforcing it site-wide, avoids the same duplicate-content problem as the www issue above — /page and /page/ can otherwise be crawled and indexed as two separate URLs.

When to Use a Rewrite vs Other Approaches

SituationBest approachWhy
Permanently moved page or restructured URL301 redirect via .htaccessPasses link equity, tells search engines the change is permanent
Temporary maintenance or A/B test302 redirectSignals the change is not permanent, preserves original URL's indexing
Two URLs should show identical content but only one should be indexedCanonical tag, not a redirectBoth URLs may need to stay accessible (e.g., filtered product listings)
Internal routing for a framework/CMS front controllerInternal rewrite (no R flag)URL should stay the same for the user; only the server-side handling changes
Blocking access to a directory or file typeDeny/Require directives, not rewriteAccess control is a different directive family from URL rewriting

Best Practices

  • Always back up your existing .htaccess file before adding new rules — a single syntax error can take the entire site offline with a 500 Internal Server Error.
  • Add RewriteEngine On only once per file, at the top, before any rules.
  • Order matters. Apache processes rules sequentially and restarts matching from the top after most rewrites, so put more specific rules before general catch-alls.
  • Use 301 for anything you intend to be permanent. Search engines cache 301s more aggressively and pass ranking signals to the new URL; 302s are treated as temporary and don't fully transfer that signal.
  • Avoid chaining multiple redirects (A to B to C). Each hop adds latency and some link equity is lost at every step — always redirect straight to the final destination.
  • Test in a staging environment first if you have one, or test each rule individually with a tool that shows the actual HTTP response headers rather than trusting the visual page load.
  • Keep CMS-generated rewrite blocks (like WordPress's marked section) untouched and add your custom rules outside of them, so plugin or core updates don't overwrite your work.
  • Comment your rules with # lines explaining why each one exists — six months later, an unexplained regex is much harder to safely modify.

Limitations

This tool generates syntax for Apache's mod_rewrite, which is not universal. Nginx uses an entirely different directive syntax (location blocks and rewrite directives inside the server config, not a per-directory .htaccess file), and IIS uses its own URL Rewrite module with XML-based configuration. Rules generated here will not work unmodified on those servers.

.htaccess rewriting also requires that your hosting environment has mod_rewrite enabled and that AllowOverride is set to permit rewrite rules in that directory — most shared hosting has this on by default, but some locked-down or high-performance configurations disable per-directory .htaccess processing entirely in favor of rules baked into the main server config for performance reasons. If your rules don't seem to take effect at all, that's usually the first thing to check with your host.

Generated rules are a starting point, not a guarantee. Complex sites with existing rewrite logic (WordPress permalinks, e-commerce platforms, custom routing) can interact with new rules in unexpected ways, and testing on your actual site remains necessary before relying on any generated rule in production.

Frequently Asked Questions

Does adding a rewrite rule slow down my site?

Each additional rule adds a small amount of processing time per request since Apache evaluates rewrite conditions on every matching request. For a handful of rules this is negligible; sites with hundreds of accumulated legacy redirect rules can see measurable overhead, which is one reason to periodically clean up old rules that are no longer needed.

What's the difference between a redirect and a rewrite?

A redirect sends the browser a new URL and an HTTP status code (301 or 302), so the address bar changes and the browser makes a second request. A rewrite (without a redirect flag) changes what content Apache serves internally without the visitor ever seeing a different URL — the address bar stays exactly as typed.

Why isn't my new rewrite rule working?

The most common causes are: mod_rewrite not enabled on the server, AllowOverride not permitting rewrites in that directory, a rule placed after a conflicting rule with the [L] flag that stops processing earlier, browser or server-side caching of the old response, or a typo in the regex pattern that simply doesn't match the intended URL.

Should I use 301 or 302 for my redirect?

Use 301 when the change is permanent — old page gone for good, replaced by a new URL. Use 302 only for genuinely temporary situations, like a maintenance page or a short-lived campaign redirect, since 302s don't pass ranking signals the same way and search engines may keep the original URL indexed instead of the target.

Can I test a rewrite rule without risking my live site?

Yes — ideally on a staging copy of the site with an identical server configuration. If that's not available, add one rule at a time, check the site immediately after each change, and keep the previous version of your .htaccess file saved so you can restore it instantly if something breaks.

Will these rules work on Nginx or a Windows/IIS server?

No. The output here is Apache mod_rewrite syntax specific to .htaccess files. Nginx requires rewrites written in its own location/rewrite directive format inside the server block, and IIS uses its separate URL Rewrite module. The underlying logic (match a pattern, redirect or rewrite to a target) is similar, but the syntax is not interchangeable.


Free Software