Dev
.htaccess Redirect Generator
Apache redirect syntax is easy to get slightly wrong — a missing RewriteCond, a backwards flag, or a regex that redirects everything instead of just one page, and suddenly the whole site loops or throws a wall of 404s right after a deploy. This generator produces the exact block Apache expects for ten common redirect scenarios, from a single-page 301 to full www and HTTPS normalization, so you can paste working rules into .htaccess without re-deriving the regex from a decade-old blog post every single time you need one. Single-URL and directory redirects use the Old URL and New URL fields directly, so entering /old-page and /new-page produces a working Redirect 301 line immediately, with a clear fallback message if either field is left blank. The other eight types — www-to-non-www, HTTP-to-HTTPS, wildcard subdomains, trailing slash handling, extension removal, and maintenance mode — generate complete RewriteEngine, RewriteCond, and RewriteRule blocks with the right flags already set, since those rules follow a fixed, well-tested pattern regardless of your specific domain or paths. Developers and site migrators use it to avoid redirect loops, preserve accumulated SEO value during a domain move or rebrand, and stand up a maintenance page with an IP allowlist in the two minutes before a risky deploy.
How to use
- Choose your options above
- Click Generate
- Copy your result
Detailed instructions
- Choose the Redirect Type that matches what you need, such as 301-single or http-to-https.
- For '301-single' or '301-directory', fill in Old URL and New URL with the paths you're redirecting.
- Click generate and copy the resulting lines exactly, including the RewriteEngine and RewriteCond lines where present.
- Back up your existing .htaccess file before pasting in the new rule.
- Paste the snippet into .htaccess, typically near the top of the file, above other RewriteRule blocks.
- Reload the affected URL in a private browser window to confirm the redirect fires correctly.
Use Cases
- •A developer migrating a blog from /old-post to /new-post and needing a clean 301 that preserves search rankings
- •A site owner forcing all traffic from www.example.com to example.com after a rebrand to a shorter domain
- •An agency enforcing HTTPS on a freshly issued SSL certificate so no page loads over plain HTTP
- •A team putting up a maintenance page during a database migration while still letting the office IP through
- •A developer removing .html extensions from every URL after switching to a framework that serves clean routes
Tips
- →Always keep a backup copy of .htaccess before editing it — a single syntax error can return a 500 error for the entire site.
- →Test 301 redirects in a private/incognito window, since browsers cache permanent redirects aggressively and may hide a mistake.
- →Place RewriteCond lines immediately above the RewriteRule they apply to — Apache only checks conditions directly preceding a rule.
- →Use 302 instead of 301 for the maintenance-mode rule since it's temporary; this generator already sets that flag correctly.
- →When combining multiple rule blocks in one file, put HTTPS and www-normalization rules first so later rules only ever see the canonical URL.
- →For wildcard subdomain redirects, double-check the domain in the RewriteCond line matches your real domain before deploying.
FAQ
how do I redirect one specific old page to a new one
Set Redirect Type to '301-single', enter the old path in Old URL (e.g. /old-page) and the destination in New URL (e.g. /new-page or a full https:// address). The generator outputs a single `Redirect 301` line — paste it into your .htaccess file above any existing RewriteRule blocks.
why do I get a redirect loop with the www or https rules
Redirect loops usually happen when two separate rules both try to rewrite the same request in opposite directions — for example a www-to-non-www rule and an HTTP-to-HTTPS rule that conflict on host and scheme at the same time. Combine them into a single rule block, or place the HTTPS rule before the www rule so each request only gets rewritten once per pass.
What does the [R=301,L] flag actually do?
R=301 tells the browser this is a permanent redirect, which passes SEO value to the new URL and gets cached by browsers and search engines. L tells Apache to stop processing further rewrite rules once this one matches, which prevents the request from being redirected again by a rule further down the file.
is .htaccess the right place for all of these redirects
.htaccess works well for small to medium sites, but on high-traffic Apache servers it is checked on every request and can add latency if you have many rules. If you control the main server config (httpd.conf or a virtual host file), moving these rules there instead is faster since Apache doesn't have to re-parse them per request.
Can I test a redirect rule before putting it on a live site?
Yes — back up your current .htaccess file first, then add the new rule and load the page in a private/incognito browser window, since browsers cache 301 redirects aggressively. If something breaks, restore the backup file immediately; a syntax error in .htaccess can take down the whole site until it's fixed.
You might also like
Popular tools from other categories that share themes with this one.
Try these next
More free tools from other corners of the catalog, picked by shared themes.