Build redirect rules for single URLs, www, HTTPS, domain moves and regex patterns. Copy the code for .htaccess, Nginx, Next.js or Cloudflare, then test the redirect chain before you deploy.
Add a redirect rule
Generated redirect code
# Add a rule and your .htaccess code will appear here.
Test a URL (see where it ends up)
No rules yet. Add a rule to see the result here.
The tester follows Apache and Nginx behavior: it applies your rules in list order, then checks the new URL again.
Before you deploy
Back up your current config first. For Nginx, run nginx -t to check the syntax before you reload. After the change, open the old and new URLs in a browser to confirm the result.
How Redirects Work in .htaccess, Nginx, Next.js and Cloudflare
A redirect tells a browser or search engine crawler to load a different URL than the one it asked for. You need one whenever a page moves, a domain changes, or you want only one version of your hostname to stay live.
Where you write the rule depends on how your site is served. Apache reads .htaccess files. Nginx uses server and location blocks in its config. A Next.js app can define redirects in next.config.js. Cloudflare Pages reads a plain text _redirects file from your build output. Each uses a different syntax, so a rule that works in one does not paste into another.
This tool covers six common cases: a single URL, www or non-www, HTTP to HTTPS, a domain move, trailing slashes, and regex patterns. Add as many rules as you need, switch between the four formats, and test any URL to see every hop it takes.
When You Need a Redirect Rule
You changed your URL structure
After a redesign or a CMS change, old URLs should send visitors and crawlers to the matching new pages instead of a 404.
You want one hostname and HTTPS only
Redirect example.com or www.example.com to a single version, and send all http:// requests to https://.
You are moving to a new domain
Send every old URL to the same path on the new domain, or send everything to the new home page if the old pages no longer exist.
You host on Next.js or Cloudflare Pages
There is no .htaccess file there. Get the next.config.js entries or the _redirects lines instead, and see which rules each one cannot express.
Create and Test Redirect Rules in 4 Steps
- Pick a rule type: single URL, www or non-www, HTTP to HTTPS, domain move, trailing slash, or regex pattern.
- Fill in the fields, choose a status code (301, 302, 307 or 308), and select Add rule. Repeat for each rule.
- Switch between the .htaccess, Nginx, Next.js and Cloudflare tabs, then copy the code or download the file.
- Enter a URL in the tester to see every redirect it goes through. Fix any loop or extra hop before you deploy.
Note: Domains and paths you enter are cleaned up for you. Pasting https://www.Example.com/ into a domain field gives example.com.
Before You Deploy the Config
- Back up your current .htaccess or Nginx config first. A syntax error can take the whole site offline.
- For Nginx, run nginx -t before you reload. The generated server blocks for port 443 contain placeholder certificate paths that you must replace.
- Rules run in order, so keep specific rules above broad patterns. Use the arrows in the rule list to reorder them.
- In .htaccess, Apache matches regex rules against the path without its leading slash. The tool removes the leading slash from your pattern for you.
- A _redirects file is not applied to requests served by Pages Functions, and Next.js redirects do not run in a static export.
- The tester follows Apache and Nginx behavior. Always open the old and new URLs on your live site after you deploy.
HTTP Redirect Status Codes: 301 vs 302 vs 307 vs 308
Pick the code that matches how long the move lasts and whether the request method must stay the same.
| Code | Name | Use it when | How Google treats it |
|---|---|---|---|
| 301 | Moved Permanently | A page, domain, hostname or protocol has changed for good | Permanent: strong signal that the new URL is canonical |
| 302 | Found | The move is short-term, such as a campaign or maintenance page | Temporary: weak signal that the new URL is canonical |
| 307 | Temporary Redirect | Like 302, but the browser must repeat the same method (POST stays POST) | Temporary: weak signal that the new URL is canonical |
| 308 | Permanent Redirect | Like 301, but the browser must repeat the same method | Permanent: strong signal that the new URL is canonical |
Next.js uses 308 for permanent redirects and 307 for temporary ones by default. This tool writes a statusCode property when you choose 301 or 302 so that the exact code is sent.
Redirect Setup Tips for SEO and Site Moves
A few choices that decide whether a redirect setup stays simple or turns into a cleanup job.
Match the format to where your site runs
Use .htaccess on Apache and Nginx rules on a server you manage. Use next.config.js for a Next.js app that runs on a server. Use _redirects for Cloudflare Pages. The _redirects file handles fixed paths and simple wildcards only, so hostname, HTTPS and domain-level rules need to be set up in the Cloudflare dashboard.
Pick one hostname and one protocol
example.com, www.example.com, http:// and https:// can all serve the same page. Redirecting everything to one version gives search engines a single address for each page and keeps your links consistent.
On a domain move, keep the path
Map each old URL to its matching page on the new domain, so old-domain.com/blog/post-1 lands on new-domain.com/blog/post-1. Send visitors to the new home page only when the old pages have no equivalent.
Avoid redirect chains
Combining an HTTPS rule and a www rule can send a visitor through two or three redirects. Each hop is an extra request. Use the tester, then point the first rule at the final URL so a visitor reaches the page in one step.
Redirect Loops, Chains and Other Common Mistakes
A redirect loop shows "too many redirects"
Two rules send a URL back and forth, or your server and a CDN or app framework both redirect the same request. The browser gives up after a few hops.
💡 See the solution▼
A visitor goes through two or three redirects
A request for http://www.example.com/page first goes to HTTPS, then to the non-www host, which adds a hop for every rule that matches in turn.
💡 See the solution▼
A permanent move uses a 302
A page moved for good but the rule sends a 302. Google treats a temporary redirect as a weak signal that the new URL is canonical, so the old URL can stay in search results.
💡 See the solution▼
Next.js redirects do nothing after export
You added redirects to next.config.js but build with output: "export". A static export does not support redirects, so the entries are never used.
💡 See the solution▼
A Cloudflare rule is missing from _redirects
You expected the www, HTTPS or domain move rule to appear in the _redirects tab, but it shows up as a comment.
💡 See the solution▼
Nginx fails to reload after you paste a server block
The generated blocks for port 443 contain placeholder ssl_certificate paths. Nginx cannot load a file that does not exist.
💡 See the solution▼
Redirect Setup FAQ
Q.Should I use a 301, 302, 307, or 308 redirect?
A. Use 301 or 308 when a URL has moved for good, such as a page move, a domain move, or a switch to HTTPS or www. Google treats permanent redirects as a strong signal that the new URL should be the canonical one. Use 302 or 307 when the move is temporary, such as a short campaign or maintenance page. Google treats those as a weak signal. 307 and 308 behave like 302 and 301, but they require the browser to repeat the same request method, so a POST stays a POST.
Q.Where do I put the .htaccess redirect code?
A. Paste it into the .htaccess file in the root folder of your site on an Apache server. Create the file if it does not exist. The generated code uses mod_rewrite, so that module must be enabled. After you save, open the old URL in a browser and check that it lands on the new one.
Q.Where does the Nginx redirect code go?
A. Rules that start with a server block are added as separate server blocks. The location rules go inside your existing server block. Nginx has no .htaccess file, so edit the site's config file instead, for example one under /etc/nginx/sites-available/. Run nginx -t to check the syntax, then reload Nginx. The server blocks that listen on port 443 include placeholder certificate paths. Replace them with your own before you reload.
Q.How do I add redirects to a Next.js app?
A. Add a redirects() function to next.config.js and paste the generated entries into the array it returns. Next.js sends a 308 when permanent is true and a 307 when it is false. For a 301 or 302, the tool writes a statusCode property instead, which Next.js accepts in place of permanent. Redirects in next.config.js do not work with a static export (output: "export"). Next.js passes the query string through to the destination.
Q.How do I set up redirects on Cloudflare Pages?
A. Save the output as a file named _redirects, with no extension, in your build output folder. Each line has a source, a destination, and a status code. A _redirects file allows 2,000 static and 100 dynamic redirects. It supports fixed paths, a single wildcard (*) with :splat, and :placeholders, but not domain-level redirects or regex. Rules the file cannot express, such as www, HTTPS, and domain moves, appear as comments in the output so you can set them up in the Cloudflare dashboard.
Q.Should I use www or non-www?
A. Neither is better. What matters is that you pick one and redirect the other to it, so search engines see a single address for each page. Choose the version you already use in links and in Google Search Console, then add one www rule and one HTTP to HTTPS rule.
Q.Does the redirect keep the query string?
A. Apache, Nginx, and Next.js output pass the query string on, so /old?id=5 goes to /new?id=5. The one exception is a domain move set to send everything to the home page, which drops the query string in the Apache and Nginx output.
Q.What causes a redirect loop, and how do I find it?
A. A loop happens when two rules send a URL back and forth, or when your server and another layer, such as a CDN or your app framework, both redirect the same request. Enter a URL in the tester below the code. It follows every redirect, shows each hop, and warns you when a URL comes back to a page it already visited.
Q.Is anything I enter sent to a server?
A. No. The code and the redirect tester run in your browser only. The domains and paths you type are not uploaded.
Your feedback
makes this tool better.
Tell us which features you'd like, what should be fixed, or which new tool you'd like to see. An engineer reads every submission and uses it to guide development.