.htaccess Redirect Generator

Generate .htaccess redirect rules for 301, 302, and wildcard redirects. Apache-ready syntax, instant output. Free, no signup needed.

Generate .htaccess Redirect Rules Without Writing Apache Syntax From Memory

Redirect rules in `.htaccess` files are one of those things that look straightforward in documentation but become fiddly in practice. The Apache directive syntax has several valid forms, the order of parameters matters, regex patterns require escaping in the right places, and a malformed `.htaccess` entry doesn't fail gracefully—it either produces a 500 Internal Server Error or silently does the wrong thing. Our free `.htaccess` redirect generator produces correct, ready-to-paste Apache redirect rules from simple URL pair inputs, so you get working redirect syntax without needing to memorize directive parameters or debug regex escaping issues.

Enter your old URL and new destination URL—one pair per line—and the tool generates the correct `.htaccess` directive for each. Choose between 301 permanent and 302 temporary redirects depending on whether you're performing a permanent migration or a short-term routing change. The output is Apache-compatible syntax that you can paste directly into your `.htaccess` file.

Understanding Apache Redirect Directives

Apache's `.htaccess` file supports multiple redirect mechanisms with different syntax and capabilities. Understanding which directive to use for each situation produces cleaner, more maintainable redirect configuration.

The Redirect Directive (mod_alias)

The simplest redirect syntax uses the `Redirect` directive from Apache's mod_alias module: `Redirect 301 /old-path https://example.com/new-path`. This directive matches the exact URL path you specify—the old path—and redirects requests for it to the new URL with the specified HTTP status code. It's the right choice for simple, exact-match redirects of specific pages: a blog post that moved, an old product page that now lives at a new URL, or a page that was consolidated into another.

The RewriteRule Directive (mod_rewrite)

For more complex redirects—pattern matching, capturing URL segments, conditional redirects, or redirects based on query strings—mod_rewrite's `RewriteRule` directive provides full regex-based URL manipulation. A basic RewriteRule redirect looks like: `RewriteRule ^old-path$ https://example.com/new-path [R=301,L]`. The `R=301` flag sets the redirect status code; `L` marks this as the last rule to evaluate when it matches, preventing subsequent rules from also matching.

RewriteRule's power comes from capture groups. To redirect all URLs under an old directory to a new one while preserving the path: `RewriteRule ^old-section/(.*)$ https://example.com/new-section/$1 [R=301,L]`. The `(.*)` captures everything after "old-section/" and `$1` inserts it into the destination URL. This pattern enables a single rule to handle an entire directory's worth of URL changes.

When to Use 301 vs. 302 Redirects

The HTTP status code you choose has direct implications for both user experience and SEO. Getting this choice right—especially in migration contexts—matters more than most developers initially realize.

A 301 Permanent Redirect tells both browsers and search engine crawlers that the resource at the old URL has permanently moved to the new URL. Search engines should transfer the link equity (PageRank) accumulated at the old URL to the new URL, update their index to point to the new URL, and stop crawling the old one. Browsers typically cache 301 redirects aggressively, meaning repeat visitors won't even hit your server—they'll be redirected client-side. Use 301 for any redirect that should persist: URL structure changes, domain migrations, HTTP to HTTPS upgrades, moving content to a new path permanently.

A 302 Temporary Redirect tells browsers and crawlers that the resource has temporarily moved, but the original URL remains valid and will eventually be restored. Search engines retain the original URL in their index and do not transfer link equity to the destination. Browsers should not cache 302 redirects as aggressively. Use 302 for A/B testing alternative page versions, geolocation-based routing where the user is temporarily directed to a region-specific page, maintenance mode redirects, and any redirect where the original URL will return.

A common mistake is using 302 when 301 is appropriate, particularly during site migrations. The consequence is that the new URLs don't inherit the link equity and search rankings of the old ones, which can cause significant traffic loss that persists long after the migration is complete. When in doubt about a permanent versus temporary distinction, 301 is usually the safer choice for production site changes.

Common .htaccess Redirect Scenarios

HTTP to HTTPS Migration

Forcing all HTTP traffic to HTTPS is one of the most common and important redirect configurations for any site. The standard `.htaccess` approach uses RewriteEngine:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

The condition checks whether HTTPS is not already active, and the rule redirects to the HTTPS version of the exact same URL.

Non-WWW to WWW (or WWW to Non-WWW)

Canonicalizing your domain to consistently use or not use the www subdomain prevents duplicate content issues: `RewriteCond %{HTTP_HOST} !^www\. [NC]` followed by `RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]`. Flip the condition to remove www instead of adding it.

Bulk URL Migration After a CMS Change

When migrating from one CMS to another—WordPress to a headless system, Drupal to a static site, Joomla to a custom build—URL structures often change significantly. Generating a redirect map from old to new URLs and converting it to `.htaccess` rules handles the migration's SEO impact. Our tool handles this case efficiently: paste a list of old-URL new-URL pairs and get all the redirect rules in one operation.

Free, Private, and Ready to Deploy

The `.htaccess` redirect generator runs entirely in your browser. No URLs or redirect configurations are transmitted to any server. The tool is completely free with no account required. Generate your rules, copy them, and paste them into your `.htaccess` file—working Apache redirect syntax in seconds.

Frequently Asked Questions

Is the .htaccess Redirect Generator free to use?
Yes, this tool is completely free with no usage limits, no registration required, and no hidden costs. You can use it as many times as you need.
Does the .htaccess Redirect Generator store my data?
No. All processing happens locally in your web browser. Your data never leaves your device and is not stored on any server. When you close the page, the data is gone.
What is the difference between a 301 and a 302 redirect?
A 301 is a permanent redirect—it tells search engines and browsers that the old URL has moved permanently and they should update their records. A 302 is a temporary redirect—the old URL is still valid and will return in the future. Use 301 for SEO-preserving migrations; use 302 for short-term redirects.
Does my web server need to support mod_rewrite for htaccess redirects?
Basic Redirect directives work with Apache's mod_alias, which is enabled by default on most Apache installations. RewriteRule-based redirects require mod_rewrite to be enabled. Most shared hosting providers have both enabled. Check with your host if redirects are not working.