.htaccess Redirect Generator

Generate Apache .htaccess redirect rules for 301 (permanent) and 302 (temporary) redirects. Force HTTPS, handle www/non-www preferences, and get production-ready code with safety warnings.

Redirect Configuration

301 passes ~90-99% of link equity. Use 302 only for temporary situations.
The path you want to redirect FROM (e.g., /old-page) or a full URL.
The full destination URL including protocol (e.g., https://example.com/new-page).

Global Rules

Quick samples:

About the .htaccess Redirect Generator

This tool generates Apache .htaccess redirect rules based on your input configuration. It produces production-ready code for both simple page redirects and global rules (HTTPS enforcement, www canonicalization).

301 & 302 Support

Choose between permanent (301) and temporary (302) redirects depending on your use case.

Force HTTPS

Automatically generate RewriteCond/RewriteRule rules to redirect all HTTP traffic to HTTPS.

www / non-www Canonicalization

Choose a preferred domain version and redirect all traffic to it for consistent SEO signals.

301 vs 302: Which Should You Use?

The difference between 301 (Permanent) and 302 (Temporary) redirects is critical for SEO:

  • 301 (Permanent):Tells search engines the page has moved permanently. Passes approximately 90-99% of link equity to the new URL. The old URL is deindexed and replaced with the new one. Use for: site migrations, URL restructuring, domain changes, permanently moved content.
  • 302 (Temporary):Tells search engines the move is temporary. Does not pass full link equity. The old URL remains indexed. Use for: maintenance pages, A/B testing, seasonal landing pages, temporary redirects.

Best Practices for .htaccess Redirects

  • Always use 301 redirects for permanent URL changes and site migrations.
  • Redirect to the most relevant page — avoid redirecting everything to the homepage.
  • Keep redirect chains short (ideally 1 hop). Long chains slow down page loads and dilute SEO value.
  • Test all redirects after deployment using a redirect checker tool.
  • Keep a backup of your working .htaccess file before making changes.
  • Use IfModule mod_rewrite.c wrappers to prevent 500 errors if mod_rewrite is disabled.
  • Avoid mixing mod_alias (Redirect) and mod_rewrite (RewriteRule) rules that match the same URLs — they process at different phases and can conflict.
  • For high-traffic sites, move frequently-used rewrite rules to your Apache virtual host configuration instead of .htaccess for better performance.

Why Proper Redirects Matter for SEO

Redirects are not just about user experience — they directly impact your search rankings. When you change a URL without a proper 301 redirect, you lose all the SEO authority built up by that page. Search engines rely on redirects to discover new content locations, consolidate ranking signals, and provide accurate search results. Common scenarios where proper redirect management is critical include:

  • Site migrations — Moving to a new domain or CMS requires a complete redirect map to preserve rankings.
  • URL restructuring — Changing your URL hierarchy (e.g., /blog/post to /resources/post) needs careful redirect planning.
  • HTTPS migration — Switching from HTTP to HTTPS requires a 301 redirect to ensure all traffic uses the secure protocol.
  • Content consolidation — Merging multiple pages into one needs redirects from the old URLs to the new canonical page.
  • Removing outdated content — Deleted pages should return 410 (Gone) or redirect to relevant alternatives, not 404 (Not Found).

Frequently Asked Questions

A 301 redirect tells search engines the page has moved permanently and passes approximately 90-99% of link equity (ranking power) to the new URL. A 302 redirect signals a temporary move and does not pass full link equity. For SEO purposes, use 301 for permanent URL changes like site migrations or restructuring, and use 302 only for temporary situations like maintenance pages or A/B testing where you plan to restore the original URL.
Redirect rules should be placed at the top of your .htaccess file, before any other rules. For Redirect directives (mod_alias), place them before any RewriteRule directives (mod_rewrite) to avoid conflicts. If you mix both mod_alias and mod_rewrite rules, the processing order can produce unexpected results — it is generally best to choose one method and stick with it throughout the file.
Yes, but with caution. Apache processes mod_alias (Redirect) and mod_rewrite (RewriteRule) at different phases of request processing. Redirect directives run first during URL-to-filename translation, while RewriteRule directives run later. This can lead to unexpected behavior if both sets of rules match the same URL. For consistent results, choose either Redirect directives for simple redirects or mod_rewrite for complex conditional redirects. Our generator uses Redirect for simple path-to-URL redirects and RewriteRule for conditional rules like HTTPS and www forcing.
Yes — even a single syntax error in your .htaccess file can cause a 500 Internal Server Error, taking your entire site offline. Always test new rules on a staging environment first and keep a backup of your working .htaccess file. Common mistakes include missing spaces, incorrect regex patterns, unclosed IfModule tags, and conflicting directives. If you get a 500 error after uploading a new .htaccess file, rename it via FTP (e.g., htaccess.bak) to restore access, then debug the rules.
RewriteEngine On enables Apache's mod_rewrite module for the current directory context. It must be included before any RewriteRule or RewriteCond directives. Without it, mod_rewrite rules are silently ignored — no error is thrown, but no rewrites or redirects happen either. You typically only need one RewriteEngine On per .htaccess file, placed inside an IfModule mod_rewrite.c block to prevent errors if the module is not installed.
Choose one and consistently redirect to it. There is no SEO advantage to www over non-www (or vice versa) — search engines treat them as distinct origins. Pick whichever you prefer for branding or technical reasons, then use a permanent 301 redirect to force all traffic to your chosen version. Our generator lets you create both www and non-www rules. Whichever you choose, update your canonical URLs, sitemaps, and internal links to match.
This condition checks whether the current request is using HTTPS. When the condition matches (HTTPS is off, meaning the request arrived over HTTP), the following RewriteRule redirects the visitor to the HTTPS version of the same URL. This is the standard approach for forcing SSL on your entire site. The %{HTTPS} server variable returns "on" for HTTPS requests and "off" for HTTP requests. Combine this with a 301 redirect for permanent HTTPS enforcement.
To redirect an entire old domain to a new domain, use: RewriteCond %{HTTP_HOST} ^olddomain\.com$ [NC] followed by RewriteRule ^(.*)$ https://newdomain.com/$1 [R=301,L]. Place these rules inside an IfModule mod_rewrite.c block. Make sure the old domain's DNS still points to your server and that Apache is configured to serve the .htaccess file for that domain. This approach preserves the full URL path (the /$1 captures everything after the domain).
Redirect (mod_alias) maps one URL path to another URL using simple prefix matching — if the requested URL starts with the specified path, the redirect applies. RedirectMatch is similar but uses regular expressions for more flexible pattern matching. RewriteRule (mod_rewrite) is the most powerful option, supporting complex conditions (RewriteCond), server variable checks, and advanced pattern matching. For simple page-to-page redirects, Redirect is sufficient. For conditional rules (e.g., HTTPS enforcement based on hostname), use RewriteRule.
Indirectly, yes. Each redirect adds an extra HTTP round trip before the final page loads, increasing time-to-first-byte (TTFB). Long redirect chains (Page A → Page B → Page C) significantly slow down page loads. Google recommends keeping redirect chains to a single hop. Additionally, complex .htaccess files with many RewriteCond and RewriteRule directives can increase Apache's per-request processing time, especially on high-traffic sites. For best performance, move frequently-used redirect rules to your server's main configuration file (httpd.conf or an Apache site config).
Reviewed Jun 2026 · Sources and limitations

Review details: 2026-06-10 · Marc LaClear · v1.0

Reference sources:

Known limits:

  • Checks are based on publicly fetchable HTML, response headers, and browser-side input. They do not use private Google Search Console, analytics, or ranking data.
  • Scores and warnings are diagnostic aids, not guarantees of ranking improvement or Google indexation.
  • Pages blocked by robots.txt, login walls, bot protection, heavy JavaScript, or network timeouts may return incomplete results.
  • Validate critical fixes with official Google tools such as Search Console, Rich Results Test, Lighthouse, and your own crawl data.

Report an issue with this tool