.htaccess Redirect Generator
301 redirects for Apache and Nginx, with a loop tester. Runs in your browser.
About this .htaccess redirect generator
This .htaccess redirect generator writes 301 and other redirect rules for Apache, with matching Nginx config, for single pages, whole folders, old domains and regex patterns. It also forces HTTPS and www or non-www in one hop, and tests any URL against your rules before you upload anything.
Add your rules in plain form fields: old address, new address, status code. The tool writes the RewriteRule or Redirect lines, escapes the dots and spaces, and handles old URLs with query strings like product.php?id=12, which a plain Redirect line can't match. Loops, duplicates and redirect chains are flagged as you type.
It's for anyone changing URLs: a site move, a new permalink structure, a cleanup of old campaign pages. All of it runs in your browser, so no URL list leaves your computer.
Features
Four kinds of redirect
Single pages, whole folders (everything under /blog/ goes to /articles/ with the rest of the path kept), whole domains, and regex patterns with $1 captures. Each rule can be 301, 308, 302, 307 or 410 Gone.
HTTPS and www in one hop
Force HTTPS, add or remove www, and add or remove trailing slashes. HTTPS and www are combined into a single rule, so http://www.example.com goes straight to https://example.com instead of bouncing twice.
Works behind Cloudflare
Tick the proxy option and the HTTPS check reads the X-Forwarded-Proto header instead of %{HTTPS}. That stops the endless loop you get when a CDN talks to your server over plain HTTP.
Nginx equivalents
Switch to Nginx for server blocks that handle HTTP to HTTPS, www and domain moves, plus location blocks for pages and folders. Old URLs with query strings use a server-level check, so your PHP location keeps working.
Loop and chain detection
Rules that point to themselves, folders redirected into their own subfolder, duplicate sources and A to B to C chains are marked on the rule. Fix chains rewrites every page rule to go straight to its final destination.
URL tester
Type any URL and see each hop: the status code, the new URL and which rule fired. It stops and warns if the rules loop.
How to use the .htaccess redirect generator
- 1Set HTTPS, www and trailing slash for the whole site.
- 2Add page, folder or domain rules, or bulk import a list of old and new URLs.
- 3Test a URL, then copy the .htaccess or Nginx rules to your server.
When to use it
Moving to HTTPS
Tick Force HTTPS, pick www or non-www, and paste the block at the top of your .htaccess. Every http URL now answers with one 301 to the secure version.
Changing domain
Add a domain rule from old-brand.com to https://new-brand.com with Keep the path on. old-brand.com/pricing then lands on new-brand.com/pricing, which keeps the links and rankings you earned.
Site migration with hundreds of URLs
Paste the old and new URL map from your spreadsheet into Bulk import (end a path with /* for a folder), fix any chains, and test a sample of URLs before go-live.
Retiring old pages
For a sale page that's gone for good with no replacement, use 410 Gone. It says plainly that the removal is deliberate, and you're not sending visitors to an unrelated page that Google might count as a soft 404.
301 vs 302 vs 307 vs 308: which redirect should I use?
Use 301 for a permanent move. It's what search engines expect when a URL has changed for good, and they move the old URL's signals to the new one. 308 is also permanent, and it keeps the request method, so a form POST stays a POST. For normal page moves, 301 and 308 behave the same in Google.
302 and 307 are temporary. Search engines keep the old URL indexed because you've said it's coming back. They're right for a short maintenance page or an A/B test, and wrong for a site move. Both are defined in RFC 9110, sections 15.4.2 to 15.4.9.
410 isn't a redirect. It says the page is gone on purpose and won't return.
How do I redirect HTTP to HTTPS in .htaccess?
These lines, inside the mod_rewrite block, send every http request to the same address on https:
- RewriteEngine On
- RewriteCond %{HTTPS} off
- RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,NE,R=301]
Why does my redirect loop?
The most common cause is a proxy or CDN. Cloudflare in Flexible mode, and many load balancers, connect to your server over plain HTTP, so %{HTTPS} is always off and the HTTPS rule fires on every request. Turn on the proxy option, or switch Cloudflare to Full mode with a certificate on the server.
The second cause is a rule that matches its own result. Sending /blog to /blog/news with a folder rule is a loop, because /blog/news is still under /blog. The checker catches that one and the URL tester shows any other loop.
Third: an old rule in a CMS block or a parent folder's .htaccess that redirects back. Put your rules at the top of the file, above the WordPress block, and look for a second .htaccess higher up.
Redirect or RewriteRule?
Redirect and RedirectMatch come from mod_alias. They're short and readable but can't see the query string or the domain name. RewriteRule comes from mod_rewrite and can test anything, which is why HTTPS, www, domain moves and ?id= URLs always need it.
Apache runs the two modules at different stages, so mixing them in one file can make rules fire in an order you didn't expect. The default RewriteRule style writes everything with one module. Choose Redirect style only if your host doesn't allow mod_rewrite for simple page moves.
Nginx doesn't read .htaccess at all. The rules go in the server config and take effect after nginx -t and a reload.
Why use Mavros
| Mavros | Typical upload sites | |
|---|---|---|
| Rule kinds | Page, folder, domain, regex, 410 | Single pages, plus www and HTTPS |
| HTTPS plus www | One combined hop | Two separate rules, two hops |
| Query string URLs | Matched with RewriteCond | Not supported |
| Nginx | Same rules, same page | Separate tool or none |
| Loops and chains | Flagged, with a URL tester | You find out in production |
| Privacy | Runs in your browser | URL lists posted to a server |
Tips
- Back up your .htaccess before you edit it. A typo returns a 500 error for the whole site, and the old file is your fix.
- Redirect each old URL to its closest new page, not to the home page. Google treats mass redirects to the home page like soft 404s.
- Keep 301s in place for at least a year after a move, longer if old links still send traffic.
- Update your internal links and sitemap to the new URLs too. Redirects are a safety net, not the main road. The sitemap generator rebuilds the list.
- Check status codes after you upload. The HTTP status codes reference explains anything unexpected you see.
- Moving to a new country domain? Update your hreflang tags to the new URLs at the same time.
Questions
Where do I put the .htaccess redirect code?
At the top of the .htaccess file in your site's root folder, above any CMS block such as WordPress's. Apache reads the file on every request, so the change is live as soon as you save it.
Does a 301 redirect pass SEO value?
Yes. Google treats a 301 or 308 as a strong signal that the new URL replaces the old one, and moves its ranking signals over. Redirect to the most relevant new page for the best result.
How do I redirect a whole folder?
Use a folder rule: old /blog/, new /articles/. Everything under the folder keeps the rest of its path, so /blog/first-post goes to /articles/first-post. Don't point a folder into its own subfolder or it will loop.
How do I redirect an old domain to a new one?
Add a domain rule with Keep the path on, and make sure the old domain still points at a server that reads these rules. In Nginx, the tool writes a separate server block for the old domain.
How do I redirect a URL with a query string, like page.php?id=3?
Put the full old URL in a page rule. The tool adds a RewriteCond on %{QUERY_STRING} for Apache, or a $request_uri check for Nginx, and drops the old query from the new URL.
Why do I get "too many redirects"?
Your rules loop. The usual cause is an HTTPS rule behind Cloudflare or a proxy, where the server never sees HTTPS. Tick the proxy option, then use the URL tester to confirm the path ends.
Does .htaccess work on Nginx?
No. Nginx ignores .htaccess files. Use the Nginx tab and add the server and location blocks to your site's config, then run nginx -t and reload.
Is my URL list uploaded anywhere?
No. Rules, output and the URL tester all run in your browser. You can paste a full migration map without sharing it with anyone.