{ Apache Redirect Generator }

// generate apache redirect & rewrite rules in one click

Generate Apache .htaccess redirect rules, RewriteRule directives, and HTTPS force rules instantly. No coding required — free and browser-based.

Relative path, e.g. /old-page or /old/dir/
Regex without leading slash. E.g. ^old-page$
Optional condition before RewriteRule
Leave blank for any domain
One per line: /from /to — separated by space or tab
⚙️

Configure your redirect

Fill in the fields and click Generate

QUICK EXAMPLES

HOW TO USE

  1. 01
    Choose a Rule Type

    Select from Simple Redirect, RewriteRule, Force HTTPS, WWW Rules, or Bulk Redirects tabs.

  2. 02
    Fill in the Fields

    Enter your source path, target URL, and any options like redirect code or flags.

  3. 03
    Generate & Copy

    Click Generate, then copy the .htaccess rules and paste them into your server config.

FEATURES

301 / 302 / 307 / 308 mod_rewrite Force HTTPS WWW Rules Bulk Redirects HSTS Header

USE CASES

  • 🔧 Migrating site pages after a redesign
  • 🔧 Enforcing HTTPS across your entire site
  • 🔧 Consolidating www vs non-www URLs
  • 🔧 Building complex pattern-based rewrites
  • 🔧 Creating bulk redirects after URL changes

WHAT IS THIS?

The Apache Redirect Generator creates ready-to-use .htaccess rules for Apache web servers. Choose your redirect type, configure the options, and get copy-paste directives — no need to memorize mod_rewrite syntax.

RELATED TOOLS

FREQUENTLY ASKED QUESTIONS

What is the difference between 301 and 302 redirects?

A 301 is a permanent redirect — search engines transfer link equity to the new URL and update their index. A 302 is temporary — search engines keep the original URL indexed and do not pass link equity. Use 301 for site migrations and permanent URL changes.

Do I need mod_rewrite enabled for Redirect directives?

No. The simple Redirect and RedirectMatch directives use Apache's mod_alias module, which is enabled by default. Only RewriteRule directives require mod_rewrite and a RewriteEngine On declaration.

Where do I place the .htaccess file?

Place the .htaccess file in the root of your website (the directory Apache serves from, usually public_html or www). It affects that directory and all subdirectories unless overridden.

What does the [L] flag do in RewriteRule?

The [L] (Last) flag tells Apache to stop processing further rewrite rules if the current rule matches. Without it, Apache continues checking subsequent rules, which can cause unintended double-rewrites.

How do I force HTTPS without losing my URL path?

Use a RewriteCond to check %{HTTPS} is off, then rewrite to https://%{HTTP_HOST}%{REQUEST_URI}. This preserves the full path and query string while upgrading the protocol. Our Force HTTPS tab generates exactly this pattern.

Why should I prefer non-www or www — not both?

Search engines treat example.com and www.example.com as separate URLs. Having both serve content causes duplicate content issues and splits link equity. Pick one canonical form and redirect the other permanently with a 301.

What is HSTS and should I add it?

HTTP Strict Transport Security (HSTS) tells browsers to always use HTTPS for your domain, even if the user types http://. It's recommended for security but be careful: once set with a long max-age, it's hard to undo. Start with a short max-age (e.g. 300 seconds) before going to one year.

Can I have multiple redirect rules in one .htaccess?

Yes. You can combine as many Redirect, RedirectMatch, and RewriteRule directives as needed. Use our Bulk Redirects tab to generate multiple rules at once. Just ensure RewriteEngine On appears before any RewriteRule directives.

Apache Redirect Generator — Build .htaccess Rules Instantly

Managing URL redirects on an Apache web server typically means writing .htaccess directives by hand — with easy-to-mistype regex patterns and flags that can silently misbehave. This Apache Redirect Generator removes that friction. Select a redirect type, configure your paths, and receive copy-ready .htaccess code in seconds.

💡 Looking for premium web development assets? MonsterONE offers unlimited downloads of templates, UI kits, and developer resources — worth checking out.

Understanding Apache Redirect Directives

Apache offers two primary modules for redirects: mod_alias and mod_rewrite. Understanding the difference helps you choose the right tool for each job.

mod_alias provides the simple Redirect directive. It matches a static path prefix and sends the browser to a new URL. It's fast, easy to read, and requires no regex knowledge. Perfect for straightforward one-to-one URL changes.

mod_rewrite provides RewriteRule — a powerful, regex-based engine. You can match dynamic URL patterns, capture groups, inspect server variables with RewriteCond, and construct target URLs programmatically. It's the right choice for complex URL transformations like removing file extensions, restructuring URL hierarchies, or routing all traffic through a single entry point.

301 vs 302 vs 307 vs 308 — Choosing the Right Status Code

The redirect status code tells browsers and search engines how to interpret the move:

Forcing HTTPS — Best Practices

Redirecting all HTTP traffic to HTTPS is now a baseline security requirement. The recommended approach uses mod_rewrite to check the %{HTTPS} server variable:

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

This pattern is preferred over RewriteCond %{SERVER_PORT} 80 because it works correctly behind SSL-terminating load balancers and proxies that set the HTTPS variable even when the backend connection is plain HTTP.

Pair this with an HSTS header (Strict-Transport-Security) to instruct browsers to never attempt HTTP connections for your domain, eliminating the redirect round-trip entirely on subsequent visits. Start with a short max-age (e.g., 300 seconds) during testing before committing to the standard one-year value.

WWW vs Non-WWW Canonicalization

Search engines treat example.com and www.example.com as completely separate domains. Serving content on both creates duplicate content issues and dilutes link equity. Choose one canonical form — most modern sites prefer the naked (non-www) domain — and permanently redirect the other.

The preferred non-www redirect:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [R=301,L]

The backreference %1 captures the domain without the www. prefix from the RewriteCond match group.

Bulk Redirects After a Site Migration

When relaunching a site or changing CMS platforms, dozens or hundreds of URLs may change simultaneously. Bulk redirect rules protect your SEO by preserving the link equity accumulated on old URLs. Rather than using a long series of individual Redirect directives (which Apache processes linearly), consider combining patterns where possible.

For very large redirect sets (500+ rules), performance improves by placing redirect logic in Apache's main server config or a virtual host configuration instead of .htaccess, since .htaccess files are re-parsed on every request. Some server setups also support RewriteMap for hash-based lookups that are dramatically faster than sequential pattern matching.

RewriteRule Flags Reference

RewriteRule flags modify how a rule behaves. The most commonly used flags are:

Common .htaccess Redirect Patterns

Beyond the patterns this tool generates, here are common scenarios you may encounter: