Htaccess & Nginx Redirect Generator
Add your old and new URLs, tick the site-wide rules you need, such as forcing HTTPS or removing www, and copy ready-to-use redirect code for Apache .htaccess, Nginx or Netlify and Cloudflare Pages. Loops and mistakes are flagged as you type.
Bulk add from a list
How to use the Htaccess & Nginx Redirect Generator
- Enter your domain and tick the site-wide rules you want, for example Force HTTPS and www → non-www.
- Add redirect rules: the old path on the left, the new path or full URL on the right, and the redirect type. End a path with * to redirect a whole folder.
- Paste a list into Bulk add if you have many URLs (one 'old new' pair per line).
- Press Generate redirects and pick the tab for your server: Apache .htaccess, Nginx or _redirects.
- Copy or download the code, put it on your server, and test a few old URLs in a private browser window.
Redirect status codes explained
| Code | Meaning | Cached by browsers | Request method | Use it for |
|---|---|---|---|---|
| 301 | Moved Permanently | Yes, often for a long time | May change POST to GET | Pages and sites that moved for good (most SEO redirects) |
| 302 | Found (temporary) | No, unless told to | May change POST to GET | Temporary moves, maintenance pages, campaigns |
| 307 | Temporary Redirect | No, unless told to | Kept (POST stays POST) | Temporary moves of forms and API endpoints |
| 308 | Permanent Redirect | Yes | Kept (POST stays POST) | Permanent moves of forms and API endpoints |
| 410 | Gone | Yes | Not a redirect | Content removed on purpose, so search engines drop it faster than a 404 |
Status codes are defined in RFC 9110. For search engines, Google treats 301 and 308 as strong signals that the new URL should replace the old one in results, and 302 and 307 as weaker, temporary signals.
Reading the generated Apache rules
A rule such as RewriteRule ^blog/(.*)$ /articles/$1 [R=301,L] has three parts:
- Pattern
^blog/(.*)$: a regular expression matched against the path without the leading slash when it is used in .htaccess. Dots and other special characters in your paths are escaped (old-page\.html), so.only matches a real dot. - Target
/articles/$1:$1inserts whatever the(.*)group captured, so/blog/2024/hellobecomes/articles/2024/hello. - Flags:
R=301sends a 301 redirect,Lstops processing further rules,NEstops Apache from re-encoding%in the target,Ganswers 410 Gone, andNCon a condition ignores letter case.
The optional /? before $ makes /old-page and /old-page/ both match. A RewriteCond line applies only to the RewriteRule directly below it.
Redirect checklist for a site migration
- List every old URL from your sitemap, analytics and the pages with backlinks, then map each one to its closest new page rather than sending everything to the home page.
- Redirect in one hop. Avoid chains such as old → interim → new; each hop adds latency and dilutes the signal. The generator flags chains between your rules.
- Keep the redirects for at least a year, and ideally permanently, because bookmarks and external links keep using old URLs.
- Update internal links and the sitemap so they point straight to the new URLs instead of relying on redirects.
- Test with
curl -I https://example.com/old-page: you should seeHTTP/2 301and alocation:header with the new URL.
Frequently asked questions
Which redirect type should I use?
Use 301 (permanent) when a page has moved for good; search engines pass its ranking to the new URL. Use 302 or 307 for temporary moves, such as maintenance or A/B tests. 308 is a permanent redirect that, like 307, keeps the request method, which matters for forms and APIs that POST. Use 410 Gone for pages removed on purpose with no replacement.
Where do I put the .htaccess code?
Put it in the .htaccess file in your website's root folder (often public_html), above any rules added by a CMS such as WordPress. The server must run Apache with mod_rewrite enabled and allow overrides (AllowOverride All). Keep a backup: a syntax error in .htaccess causes a 500 error for the whole site.
What is the difference between mod_rewrite and Redirect?
Redirect and RedirectMatch come from mod_alias and are simple and fast, but they cannot check the host name or HTTPS. RewriteRule from mod_rewrite can, which is why the site-wide presets always use it. Apache processes mod_rewrite rules before mod_alias rules, so avoid relying on the order between the two.
How do I avoid redirect loops?
A loop happens when a URL redirects to itself, directly or through other rules, for example /a to /b and /b back to /a, or a folder rule whose target is inside the same folder. The generator warns about these. Behind Cloudflare or a load balancer, use the X-Forwarded-Proto check for HTTPS, because the server itself may only see plain HTTP.
Are query strings kept?
With Keep query string on, /old?id=5 redirects to /new?id=5. Apache RewriteRule and Redirect keep query strings by default, and the Nginx code adds $is_args$args to do the same. Turn the option off to drop them in the Apache rewrite and Nginx output. Matching on a specific query string is not supported by path redirects.
Where do the Netlify and Cloudflare Pages rules go?
Save the file as _redirects (no extension) in the folder that gets published, for example public or dist. Netlify also supports domain-level rules such as www to non-www; on Cloudflare Pages use Bulk Redirects or Redirect Rules in the dashboard for those, and HTTPS is enforced automatically on both.
How do I test my redirects?
Open the old URL in a private window, or run curl -I https://example.com/old-page and check the status code and Location header. Browsers cache 301 redirects aggressively, so test with 302 first if you are unsure, and clear the cache after changing a rule.