Free Tool

Free .htaccess Redirect Generator

Generate Apache .htaccess 301 and 302 redirect rules from old URL to new. Single redirects, force-HTTPS, and www canonicalization with correct syntax. Free, copy-paste, no signup.

to
# Redirects generated by U2L AI (u2l.ai/tools/htaccess-redirect-generator)
# Path redirects
Redirect 301 /old-page /new-page

Add to the .htaccess file in your site root. Place canonicalization rules before path redirects. Back up your existing .htaccess first.

No signup required
Free forever
GDPR compliant
Powered by U2L

Quick Answer

An .htaccess redirect generator builds the Apache directives that send visitors from an old URL to a new one. Add your source and destination paths, choose 301 (permanent) or 302 (temporary), and optionally force HTTPS or www, and the tool outputs ready-to-paste .htaccess rules. The U2L .htaccess Redirect Generator runs in your browser. Free, no signup.

Quick Facts

  • .htaccess is Apache's per-directory config file; redirects placed in the site-root .htaccess apply to the whole site.
  • 301 is a permanent redirect (passes SEO value, cached by browsers); 302 is temporary (no caching, no SEO transfer).
  • Simple path redirects use the Redirect directive: Redirect 301 /old https://example.com/new.
  • Force-HTTPS and www/non-www canonicalization use mod_rewrite (RewriteCond + RewriteRule).
  • Order matters: put canonicalization (HTTPS, www) rules before individual path redirects.
  • Only Apache reads .htaccess - Nginx and others use different syntax. Confirm your server runs Apache.
  • Browser-only and instant - rules are built locally and never sent to U2L servers.

How to generate .htaccess redirects

Add redirects, pick options, copy the rules.

  1. 1

    Add your redirects

    Enter each old path and the new destination (a path or a full URL). Add as many rows as you need with the Add redirect button.

  2. 2

    Choose 301 or 302 and canonicalization

    Pick a permanent 301 or temporary 302, then optionally enable force-HTTPS and www or non-www canonicalization with your domain.

  3. 3

    Copy into your .htaccess

    Copy the generated rules and paste them into the .htaccess file in your site root. Back up the existing file first and test a couple of URLs.

What is a .htaccess Redirect Generator?

.htaccess Redirect Generator is a tool that builds Apache .htaccess redirect rules from a simple form. You enter old and new URLs, choose the redirect type, and the generator produces the correct Redirect and mod_rewrite directives - so you do not have to remember Apache's syntax or risk a typo that takes your site down.

.htaccess is a configuration file that Apache reads on every request for the directory it sits in. Placed at your site root, it can rewrite and redirect URLs, force HTTPS, canonicalize the www prefix, set headers, and more. Redirects are its most common use: telling browsers and search engines that a URL has moved.

Getting redirect syntax right matters because the cost of a mistake is high. A misplaced rule can create a redirect loop, a 500 error, or silently send visitors to the wrong page - and because .htaccess is read on every request, a broken file can take the whole site offline. A generator produces known-good syntax and the correct directive for each job.

Developers, SEOs, and site owners use this when migrating URLs, consolidating www and HTTPS variants, retiring old pages, or restructuring a site - any time content moves and the old links must keep working.

How does a .htaccess Redirect Generator work?

For each path redirect you add, the generator emits a Redirect directive: Redirect 301 /old-page https://example.com/new-page. The first argument is the status code, the second is the source path on your domain, and the third is the destination, which can be a path or an absolute URL. Apache matches the source against incoming requests and responds with the redirect.

For canonicalization, the tool switches to mod_rewrite, which is more flexible than the basic Redirect directive. Force-HTTPS adds a RewriteCond that checks whether the connection is not secure, then a RewriteRule that sends the request to the https version of the same host and path. The www rules check the host against your domain and redirect to the canonical (www or non-www) form.

The output is ordered deliberately: canonicalization rules (HTTPS, www) go first inside an <IfModule mod_rewrite.c> guard, and individual path redirects follow. This ordering matters because you want a request normalized to its canonical host and scheme before path-level redirects evaluate, avoiding double redirects and loops.

Everything is computed in your browser; nothing is sent to U2L. The result is standard Apache syntax you paste into .htaccess. Because a broken .htaccess can return a 500 across your site, always back up the current file first and test a handful of URLs after deploying - the generator gives you correct syntax, but you still control placement and your server's module availability.

Use Cases

How marketers, businesses, and developers use .htaccess redirect generator.

Redirecting moved or renamed pages

When a page's URL changes, a 301 keeps old links and search rankings working by sending visitors and crawlers to the new address.

Forcing HTTPS across the site

Redirect all http traffic to https with a single mod_rewrite rule so every visitor gets the secure version and you avoid duplicate-content issues.

Canonicalizing www vs non-www

Pick one canonical host and redirect the other, consolidating SEO signals and preventing the same content from ranking under two hostnames.

Site migrations and restructures

Map an entire batch of old URLs to their new locations during a redesign so no inbound link or bookmark breaks after launch.

Retiring old content gracefully

Send visitors from a discontinued product or article to the most relevant replacement instead of a dead 404 that loses the visit.

Consolidating duplicate URLs

Redirect trailing-slash, index.html, or legacy variants to a single canonical URL to clean up crawl budget and analytics.

Temporary redirects for promotions

Use a 302 to point a campaign path at a seasonal landing page, then remove it later without the redirect being cached permanently.

Fixing SEO duplicate-content penalties

Resolve http/https and www/non-www splits that dilute rankings by enforcing one canonical version of every URL.

Learning Apache redirect syntax

See how form inputs translate into Redirect and RewriteRule directives, building a working mental model of mod_rewrite.

.htaccess Redirect Generator vs Alternatives

Side-by-side feature and pricing comparison with the top alternatives.

FeatureU2LManual editingHosting panelPlugin
Free, no signupVariesVaries
Correct 301/302 syntax guaranteed
Force HTTPS + www rulesManualSometimesSometimes
Works without a CMS
No server load from a plugin
Browser-only (no data sent)

.htaccess Redirect Generator vs Editing .htaccess by hand

Experienced developers edit .htaccess directly. It is fast and needs no tool once the directive syntax and mod_rewrite flags are second nature.

The risk is real: a single misplaced flag or condition can cause a redirect loop or a site-wide 500. The generator emits known-good syntax and orders canonicalization before path rules, removing the most common ways hand-edited redirects break.

.htaccess Redirect Generator vs A WordPress redirect plugin

Plugins like Redirection manage redirects inside WordPress with a friendly UI, which is convenient when your whole site is WordPress.

Plugins add PHP overhead on every request and only work within the CMS. Native .htaccess rules run at the server level - faster and applicable to any Apache site, CMS or not. This generator gives you those native rules without installing anything.

Best Practices

Back up .htaccess before editing

Because a broken .htaccess can 500 the whole site, save a copy of the current file so you can restore instantly if something goes wrong.

Use 301 for permanent moves

A 301 passes SEO value to the new URL and is cached by browsers. Reserve 302 for genuinely temporary redirects you intend to remove.

Put canonicalization before path redirects

Force HTTPS and www rules should run first so requests are normalized before path-level redirects evaluate, avoiding double redirects and loops.

Test for redirect loops

After deploying, load redirected URLs and confirm they resolve in one hop. A rule that redirects a page to itself creates an infinite loop.

Avoid chains of redirects

Redirect old URLs straight to the final destination, not through intermediate URLs. Each extra hop slows the page and dilutes SEO value.

Confirm mod_rewrite is enabled

The HTTPS and www rules need mod_rewrite. Most hosts enable it, but verify - the <IfModule> guard prevents errors if it is missing.

Keep redirects in the root .htaccess

Site-wide redirects belong in the root file. Per-directory .htaccess files only affect their own folder, which can cause confusing partial behavior.

Document each redirect with a comment

Add a short comment above non-obvious rules so future maintainers know why a redirect exists and can safely remove it later.

Common Mistakes to Avoid

Creating a redirect loop

Redirecting a URL to itself, or A to B and B back to A, sends browsers into an infinite loop. Always redirect toward the final destination only.

Using 302 for permanent moves

A temporary 302 does not pass SEO value and is not cached, so search engines keep the old URL indexed. Use 301 for moves that are permanent.

Wrong rule order causing double redirects

Placing path redirects before HTTPS/www canonicalization makes a request redirect twice. Put canonicalization first to normalize the request once.

Editing without a backup

A syntax error in .htaccess can take the entire site down with a 500 error. Skipping the backup turns a small typo into an outage.

Assuming .htaccess works on Nginx

.htaccess is Apache-only. On Nginx the file is ignored entirely; you need server-block directives instead. Confirm your server before relying on it.

Forgetting RewriteEngine On

mod_rewrite rules do nothing without RewriteEngine On. The generator includes it, but hand-written rules often omit it and silently fail.

Technical Specifications

File.htaccess in the site root (Apache)
Path redirect directiveRedirect 301|302 /source destination
Canonicalizationmod_rewrite (RewriteCond + RewriteRule)
301Permanent - passes SEO value, browser-cached
302Temporary - no SEO transfer, not cached
Required modulemod_rewrite (for HTTPS/www rules)
Rule orderCanonicalization first, then path redirects
PrivacyBuilt in your browser. No data sent to U2L.

Frequently Asked Questions

What is an .htaccess redirect?

It is an instruction in Apache's .htaccess file that sends a visitor from one URL to another. A line like Redirect 301 /old https://example.com/new tells Apache to permanently redirect requests for /old to the new address.

What is the difference between a 301 and a 302 redirect?

A 301 is permanent: it passes SEO value to the new URL and browsers cache it. A 302 is temporary: search engines keep indexing the old URL and the redirect is not cached. Use 301 for permanent moves and 302 only when temporary.

How do I redirect a single page in .htaccess?

Add Redirect 301 /old-page https://example.com/new-page to your .htaccess. The generator builds this line for each redirect you enter, with the status code and paths formatted correctly.

How do I force HTTPS with .htaccess?

Enable the force-HTTPS option. The generator outputs a mod_rewrite rule that checks if the connection is insecure and redirects it to the https version of the same URL with a 301.

How do I redirect non-www to www (or the reverse)?

Choose 'Force www' or 'Force non-www' and enter your domain. The generator produces a mod_rewrite rule that redirects the wrong host variant to your chosen canonical one, consolidating SEO signals.

Where do I put the redirect rules?

In the .htaccess file at your site root. If the file does not exist, create it. Place canonicalization rules (HTTPS, www) before individual path redirects so requests normalize first.

Why did my site break after editing .htaccess?

A syntax error in .htaccess causes Apache to return a 500 for the whole site. Restore your backup, then re-add rules carefully. This is why backing up before editing is essential.

Does .htaccess work on Nginx?

No. .htaccess is specific to Apache. Nginx ignores it and uses server-block directives instead. If you run Nginx, use the Nginx Redirect Generator rather than this one.

How do I avoid redirect loops?

Never redirect a URL to itself or set up two rules that point at each other. After deploying, load each redirected URL and confirm it resolves in a single hop to the final destination.

Can I redirect a whole folder or pattern?

Yes, with mod_rewrite patterns, though those are more advanced. For straightforward page-to-page moves, the Redirect directive this tool generates is simpler and less error-prone.

Do redirects affect SEO?

Yes - positively when done right. A 301 transfers most of the old URL's ranking value to the new one. Using the wrong code, chaining redirects, or creating loops harms SEO, which is why correct syntax matters.

What is mod_rewrite?

mod_rewrite is the Apache module that enables flexible URL rewriting and conditional redirects. The HTTPS and www rules rely on it; the generator wraps them in an <IfModule> guard so they fail safely if it is unavailable.

Can the destination be a full URL on another domain?

Yes. The destination can be a path on the same domain or a complete URL on another domain. Enter whichever you need and the generator formats the Redirect directive accordingly.

Should I redirect http and www in the same file?

Yes, and order them so canonicalization runs first. Forcing HTTPS and the canonical host before path redirects ensures each request is normalized once, avoiding multiple hops.

Is this generator free and private?

Yes. It is free with no signup, and it builds the rules entirely in your browser. Your domains and paths never leave your device.

How do I test that a redirect works?

Load the old URL in a browser or use a redirect-checking tool to confirm it returns the expected 301 or 302 and lands on the right destination in one hop. U2L's Redirect Checker can trace the full chain.

Key Terms

.htaccess
Apache's per-directory configuration file. Placed at the site root, it can redirect URLs, force HTTPS, set headers, and more, and is read on every request.
301 redirect
A permanent redirect status code that passes SEO value to the destination and is cached by browsers.
302 redirect
A temporary redirect status code that does not transfer SEO value and is not cached, so the original URL stays indexed.
mod_rewrite
The Apache module providing rule-based URL rewriting and conditional redirects, used for force-HTTPS and www canonicalization.
Canonicalization
Enforcing a single preferred URL form (one scheme, one host) by redirecting the alternatives, consolidating SEO signals.

Need redirects without touching server config?

U2L lets you create and edit redirects as branded short links - no .htaccess, no deploy, full click analytics, and editable destinations any time. Sign up free to manage redirects the easy way.

Sign up free