.htaccess Redirect Generator - Apache & Nginx Rules

Generate 301 and 302 redirect rules for Apache .htaccess and Nginx from a list of old and new URLs. Includes ready-made templates for HTTPS, www removal, and trailing slashes.

Redirect Rule Generator for Apache and Nginx

Build correct redirect rules without memorizing Apache mod_rewrite or Nginx syntax. Paste a list of old paths and their new destinations, pick 301 or 302, and get two ready-to-use blocks: one for an Apache .htaccess file and one for an Nginx server configuration. Common site-wide patterns like forcing HTTPS, removing the www prefix, and adding trailing slashes are available as one-click templates.

Developers and site owners need redirects whenever they migrate a site, restructure URLs, rename blog posts, move from HTTP to HTTPS, or consolidate www and non-www versions of a domain. SEO specialists rely on 301 redirects to pass link equity from old URLs to new ones, and agencies use bulk lists like this during content migrations with dozens or hundreds of moved pages.

A 301 tells browsers and search engines the move is permanent, so Google transfers rankings to the new URL and browsers cache the redirect. A 302 marks a temporary move and keeps the original URL in the index, which is the right choice for A/B tests or maintenance pages. The generated Apache rules use the Redirect directive for simple path mappings and RewriteRule with conditions for the site-wide templates; the Nginx output uses return and rewrite statements, which Nginx evaluates faster than regex location blocks.

Redirect chains cost real performance: each hop adds a full network round trip, often 100-300 ms on mobile connections, and Google typically follows at most 10 hops before giving up. Point old URLs directly at their final destination instead of chaining through intermediate redirects, and test with curl -I to confirm the status code and Location header before going live.

After setting up redirects, check what each status code means with our HTTP Status Codes reference and keep your sitemap current. If you are reorganizing a site, the Slug Generator helps you create clean, SEO-friendly paths for the new URL structure.

How the Redirect Generator Works

  1. 01Paste redirects as 'old-path new-url' lines, or switch to single mode for one redirect.
  2. 02Pick 301 (permanent) or 302 (temporary) and enable any templates: force HTTPS, www to non-www, trailing slash.
  3. 03The tool builds matching Apache .htaccess and Nginx configuration blocks side by side.
  4. 04Copy the block for your server, paste it into .htaccess or your Nginx config, and reload.

Setting Up Redirects the Right Way

List every moved URL as a pair per line: the old path (starting with a slash) followed by the full destination URL. The generator normalizes paths that are missing the leading slash and skips malformed lines with a clear warning, so you can paste straight from a migration spreadsheet. Choose 301 for permanent moves so search engines transfer rankings, or 302 when the change is temporary. The site-wide templates cover the three most requested patterns: forcing HTTPS with a rewrite condition on the HTTPS flag, folding www traffic onto the bare domain, and appending trailing slashes to directory-style URLs while leaving real files alone. For Apache, place the output in the .htaccess file at your document root (mod_rewrite and mod_alias must be enabled, which they are on nearly all shared hosting). For Nginx, the path redirects belong inside your existing server block, while the HTTPS and www templates are standalone server blocks; replace example.com with your domain. Reload the server and spot-check a few URLs with curl -I to confirm the status code and Location header.

When to Use the Redirect Generator

Reach for it during site migrations, domain changes, URL restructures, and HTTPS rollouts - any moment old URLs must land visitors and search engines on new ones. It is equally useful for one-off fixes, like a renamed blog post that still gets traffic from social links, and for standardizing a site on one canonical host and protocol. If you manage both Apache and Nginx environments, the side-by-side output saves you from translating syntax by hand.

Common Use Cases

  • Migrating a website to a new URL structure with a bulk list of moved pages
  • Forcing all traffic to HTTPS after installing a TLS certificate
  • Consolidating www and non-www hostnames onto one canonical domain
  • Redirecting renamed blog posts so old backlinks keep working URL Slug Generator - SEO-Friendly Slugs
  • Looking up what a 301 or 302 response actually means HTTP Status Codes - Complete Reference

Expert Tips

  • Test with curl -I before announcing a migration: it shows the exact status code and Location header without browser caching getting in the way.
  • Browsers cache 301s aggressively; while testing, use 302 first and switch to 301 once the mapping is final.
  • Keep your redirect list in version control next to your site code, so the mapping survives server moves.

Frequently Asked Questions

Should I use 301 or 302?
Use 301 when the move is permanent: search engines transfer ranking signals and browsers cache the redirect. Use 302 for temporary situations such as A/B tests or maintenance pages, where you want the original URL to stay canonical.
Where do I put the Apache rules?
In the .htaccess file in your site's document root, or directly in the virtual host configuration if you have server access (which is faster because .htaccess is evaluated on every request).
Why are the Nginx templates full server blocks?
Nginx handles protocol and hostname redirects most efficiently with dedicated server blocks that return 301 immediately, rather than rewrite rules inside your main block. The path redirects, by contrast, drop into your existing server block as location lines.
Do redirect chains hurt SEO?
Yes. Each hop adds latency and Google follows a limited number of hops. Always point old URLs directly at the final destination, and update the list when a destination moves again.

Related tools

12 suggested