Calcro
Developer Tools

.htaccess Redirect Generator

Generate correct Apache redirect rules in seconds. Supports 301, 302, 307, 410, regex patterns, domain-level rewrites, and bulk import — ready to paste into your .htaccess file.

Domain-Level Rules

URL Redirects

Rule 1
.htaccess
# Add redirects above to generate your .htaccess rules

How .htaccess Redirects Work

Apache's .htaccess file is the most common way to manage URL redirects on shared hosting and many dedicated server setups. When a browser requests a URL, Apache checks for a .htaccess file in the requested directory and applies any matching rules before serving the response. Redirect rules tell Apache to send the browser to a different URL, optionally passing along a status code that indicates whether the move is permanent or temporary.

There are two primary syntaxes for redirects: the simpler Redirect directive (ideal for one-to-one URL mappings) and the more powerful RewriteRule directive (which supports regular expressions and conditional logic via RewriteCond). This generator uses Redirect for simple paths and RewriteRule when you enable regex or domain-level rules.

When to Use Each Redirect Type

Choosing the right HTTP status code matters — it affects how search engines treat the redirect and how browsers cache it. A 301 Permanent Redirect is the workhorse for SEO. It tells Google to transfer all ranking signals from the old URL to the new one and to deindex the original. Use it for site migrations, URL restructuring, or consolidating duplicate pages.

A 302 Temporary Redirect preserves the original URL's rankings in search engines. Use it when you're running A/B tests, performing maintenance, or serving localized content that may change. The 307 code is identical to 302 but strictly preserves the HTTP method (GET, POST) — it's important for API endpoints or form submissions where method fidelity matters.

Domain-Level Best Practices

Before adding individual redirects, establish your canonical domain configuration. Every site should enforce HTTPS and choose between www and non-www. Running both versions creates duplicate content that splits your search rankings. Use our domain-level toggles to generate the correctRewriteCond + RewriteRule blocks for these foundational rules — they should appear first in your .htaccess file so they execute before any path-specific redirects.

Trailing slash consistency is equally important. Pick a convention (with or without trailing slash) and enforce it via redirect. This prevents duplicate content issues where /about and/about/ are treated as separate pages by search engines.

Frequently Asked Questions

A .htaccess file is a configuration file used by Apache web servers to control directory-level settings. It's placed in your website's root directory (or any subdirectory) and can manage URL redirects, access control, custom error pages, MIME types, and more — all without modifying the main server configuration. Changes take effect immediately without restarting the server.

A 301 redirect tells search engines and browsers that a page has permanently moved to a new URL. Search engines will transfer the old page's ranking signals (link equity) to the new URL. A 302 redirect signals a temporary move — the original URL retains its rankings and the redirect can be reversed at any time. For SEO, use 301 for permanent changes (site migration, URL restructuring) and 302 only for genuinely temporary situations.

Use a 410 status code when a page has been permanently removed and there is no replacement page to redirect to. Unlike a 404 (which tells search engines 'this might come back'), a 410 explicitly says 'this content is gone forever.' This helps Google deindex the old URL faster. Common use cases include removed products, discontinued services, or deleted blog posts with no equivalent replacement.

Use the domain-level toggle buttons above your redirect rules. Our generator produces the correct RewriteCond and RewriteRule directives for canonical domain normalization. Pick one version — www or non-www — and stick with it. Having both versions live creates duplicate content issues that dilute your SEO. The redirect should always be a 301 (permanent) so search engines consolidate rankings to your chosen version.

Yes — toggle the 'Regex' checkbox on any rule to use regular expression patterns in your source URL. This is powerful for redirecting URL patterns like /blog/2023/* to /archive/2023/* or rewriting query parameters. Common regex patterns include (.*) to match anything, ^old-section/ to match a path prefix, and (.+)\.html$ to match all .html extensions. Our generator uses RewriteRule syntax for regex-based redirects.

Absolutely — every public-facing website should run on HTTPS. Forcing HTTPS via .htaccess ensures that any HTTP request is automatically redirected to the secure version. This protects your visitors' data, improves trust signals, and is a confirmed Google ranking factor. Toggle 'Force HTTPS' in our domain-level rules to generate the correct Apache rewrite directives.

No — .htaccess files only work on Apache web servers. If your site runs on Nginx, you'll need equivalent rewrite rules in your nginx.conf file. If you're behind Cloudflare, you can use Cloudflare's Page Rules or Redirect Rules for URL forwarding instead. However, many shared hosting providers (like cPanel-based hosts) run Apache, making .htaccess the standard approach for those environments.