Write Apache redirects you can trust — and the Nginx version too
Redirects are how a site keeps its visitors and its search rankings when URLs change. The .htaccess Redirect Generator writes the Apache mod_rewrite and Redirect rules for the jobs you actually need — 301 and 302 page redirects, forcing HTTPS, choosing www or non-www, adding or removing trailing slashes, hiding .html and .php extensions, a custom 404 page, folder-to-folder moves and a whole-domain move — in the right order and with comments explaining each block.
Switch to the Nginx tab for the equivalent server blocks and location rules. Paths with spaces, brackets or dots are escaped correctly in regular expressions, redirect loops are flagged before you upload, and nothing you type leaves your browser.
How to use the .htaccess Redirect Generator
- Tick Force HTTPS and choose your www preference, trailing-slash behaviour and whether to hide file extensions. Enter your domain so host rules can be written.
- Add single page redirects (old path → new path or URL) and choose 301, 302, 307, 308 or 410 for each.
- Add folder moves when a whole section changed address, or fill in a new domain to move the entire site.
- Read any warnings, then copy or download the .htaccess file — or switch to Nginx for server blocks.
- Upload, then test a few old URLs in a private window and check the status code with HTTP Status Codes as a reference.
.htaccess Redirect Generator features
Single-hop canonical redirect
When HTTPS and www rules are both on, one combined rule sends http://www.example.com/page straight to https://example.com/page instead of chaining two 301s.
Correct rule order
Domain and protocol rules first, exact redirects next, then slash and extension tidying, then ErrorDocument — so specific redirects are never shadowed.
Regex-safe paths
Folder names are escaped for PCRE, so /blog (archive)/ becomes ^blog\ \(archive\)(/.*)?$ and keeps the rest of the path.
Loop and syntax checks
Flags redirects that point to themselves, folders moved inside themselves, query strings in Redirect paths and invalid domains.
Nginx equivalents
The same intent expressed as server blocks, return 301, try_files and error_page, with notes on where to add SSL paths.
All common status codes
301 and 308 for permanent moves, 302 and 307 for temporary ones, 410 for pages that are gone for good.
Which redirect code to use
Google treats 301 and 308 as strong permanent signals and consolidates ranking to the destination. It also follows 302s and, if they stay in place long enough, treats them as permanent, but a 301 says what you mean from day one.
| Code | Meaning | Use it when |
|---|---|---|
| 301 | Moved permanently; method may change to GET | A page or site has moved for good — passes ranking signals |
| 302 | Found (temporary) | A/B tests, maintenance, geo-redirects you will remove later |
| 307 | Temporary, method preserved | Temporary redirect of a form POST |
| 308 | Permanent, method preserved | Permanent redirect where POST must stay POST (APIs) |
| 410 | Gone | Content removed deliberately — search engines drop it faster than a 404 |
How the generated Apache rules work
RewriteCond lines set conditions and the following RewriteRule fires only when they match. %{HTTPS} !=on detects plain HTTP; %{HTTP_HOST} checks the domain; %{REQUEST_URI} carries the original path so visitors land on the same page. The flags mean: R=301 send a redirect with that status, L stop processing further rules, NE don’t re-encode special characters, NC match case-insensitively.
The simpler Redirect 301 /old /new directive comes from mod_alias and matches the path prefix exactly, passing the query string through automatically. The extension-hiding block uses %{THE_REQUEST}, the raw request line, so it redirects only what the browser asked for and never loops when the file is served internally. If your host terminates TLS at a load balancer, replace the HTTPS condition with the X-Forwarded-Proto variant included as a comment.
Avoiding common redirect problems
- Chains: http → https → non-www is three requests. The combined rule here does it in one hop. Point old redirects directly at the final URL when you change things again.
- Loops: redirecting /a to /b and /b to /a, or a folder into itself, makes browsers give up with “too many redirects”. The generator flags the cases it can see; test the rest.
- Caching: browsers remember 301s. Test with a private window or curl -I, and use 302 while you are still experimenting.
- Soft 404s: never redirect missing pages to the home page or to a 404 page; let the server return a real 404 or 410 so search engines drop the URL.
- Sitemaps and internal links: after a move, update your sitemap and internal links to the new URLs rather than relying on redirects.
.htaccess Redirect Generator FAQ
What is an .htaccess redirect generator?
A tool that writes the Apache configuration for redirects so you don’t have to remember mod_rewrite syntax. This .htaccess redirect generator covers single pages, folders, whole domains, HTTPS, www, trailing slashes, hidden extensions and custom 404 pages, and shows the Nginx equivalent.
Where do I put the .htaccess file?
In the document root of your website (often public_html or www), the same folder as your home page. It applies to that folder and everything below it. Apache must have mod_rewrite enabled and AllowOverride set to allow it — most shared hosts do.
Why doesn’t my redirect work?
Common causes: the file is in the wrong folder, mod_rewrite is disabled, a CMS rule above yours already matched with an L flag, or your browser cached an earlier 301. Test in a private window and check the server error log.
Should I redirect www to non-www or the other way?
Either is fine for SEO; what matters is choosing one and redirecting the other with a 301 so all links and signals point to a single host. Match whatever your canonical tags and Search Console property use.
Does Nginx support .htaccess?
No. Nginx reads its configuration once at startup from nginx.conf and included files. Use the Nginx tab to get the same redirects as server blocks and location rules, run nginx -t, then reload.
Will a 301 redirect keep my Google rankings?
A 301 (or 308) tells Google the move is permanent, and Google consolidates signals to the new URL over time. Redirect each old page to its most relevant new page rather than everything to the home page, and update your sitemap.