Skip to content
ZeroServer.tools

htaccess Redirect Generator

Build Apache .htaccess 301 and 302 redirect rules.

Redirect Type: 301Active Rules: 0
Redirect type
.htaccess

How .htaccess redirects work

On Apache servers, a .htaccess file can redirect old URLs to new ones using the Redirect directive (mod_alias). A 301 is a permanent move and passes SEO ranking to the new URL; a 302 is temporary. The from is a path on your site (starting with /); the to can be a path or a full URL. Rules are generated in your browser — paste them at the top of your .htaccess.

Related: the canonical tag generator, the robots.txt generator, and the htpasswd generator.

Built and maintained by Meet Shah · Last updated

What this tool is used for

  • Producing redirect rules for a batch of URLs changed in a site migration.
  • Getting the syntax right for a redirect type you use rarely.
  • Generating rules from a spreadsheet of old and new paths.
  • Producing a redirect map to review before deploying it.
  • Adding a redirect on a host where you cannot change the main server config.

Frequently Asked Questions

What is an .htaccess file?
An .htaccess file is a per-directory configuration file for Apache web servers. It lets you set URL redirects, rewrite rules, password protection, and cache headers without editing the main server configuration.
What's the difference between a 301 and 302 redirect?
301 (Permanent) tells search engines the page has moved forever — the old URL's SEO equity transfers to the new one. 302 (Temporary) tells search engines to keep indexing the old URL. Use 301 for site migrations and URL restructures.
Does .htaccess work on Nginx or other web servers?
No. .htaccess is Apache-only. Nginx uses its own server block configuration (nginx.conf). For Cloudflare Pages, use a _redirects file instead. Translate your RewriteRules to server-specific equivalents when switching.
How do I force HTTPS with .htaccess?
RewriteEngine On, then: RewriteCond %{HTTPS} off, followed by RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]. This catches all HTTP requests and permanently redirects to the same HTTPS URL.
Can I use wildcards in .htaccess redirects?
Yes. RewriteRule uses regular expressions on the request URI. '(.*)' captures everything; '^old-path/(.*)$' captures a sub-path. Reference captured groups in the replacement with $1, $2, etc.
Why is my rule not firing?
Usually one of three things: `AllowOverride` is not enabled for the directory, another rule matched first and stopped processing, or the browser cached an earlier 301. Test in a private window — a cached permanent redirect survives a server change.
What does the L flag do, and when is it not enough?
`[L]` stops processing the current rule set, but in a `.htaccess` context the whole set can re-run after an internal rewrite. `[END]`, added in Apache 2.4, stops that re-entry outright and is the correct flag for a genuine final rule.

Common errors and gotchas

  • Creating a chain where one redirect points at another, which wastes crawl budget and slows every request.
  • Writing a rule that loops, which is easy when a pattern matches its own target.
  • Using 302 for a permanent move, which does not transfer ranking signals the way 301 does.
  • Ordering rules so an early broad match prevents later specific ones from running.
  • Redirecting everything to the homepage instead of the closest equivalent page, which reads as a soft 404.

Related Web & SEO tools

Private & free — this tool runs entirely in your browser.

BluehostReliable WordPress & web hosting — exclusive pricing from $3.79/mo.affiliate