htaccess Redirect Generator
Build the redirect block, copy it, and check one URL before you upload it.
RewriteEngine On
# Page redirects. RewriteRule keeps these in the same pass as the rules below.
RewriteRule ^old-page/?$ https://example.com/new-page [R=301,L]
# Force HTTPS and drop www, in one redirect.
RewriteCond %{HTTP_HOST} ^(?:www\.)?example\.com$ [NC]
RewriteCond %{HTTPS} !=on [OR]
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteRule ^ https://example.com%{REQUEST_URI} [R=301,L]
How to use this htaccess redirect generator
- Enter the domain. Force HTTPS and Non-www are already on, which is the usual permanent setup.
- Add one old path and its new URL, or open More rules and paste a list.
- Read the warnings. A loop points a URL at itself. A chain points at another URL that also moves.
- Use Test a URL, then copy the Apache block or download the .htaccess file. The Nginx tab is the same plan for Nginx.
Redirect HTTP to HTTPS in htaccess
The HTTPS rule checks that the request is still plain HTTP, then sends the same path to https. When Non-www or www is selected, the host changes in that same redirect. A visitor who typed http://www.example.com/about lands on https://example.com/about once, not twice.
www to non-www htaccess
Choose Non-www and the file matches only www.yourdomain.com. The bare domain is left alone, so the rule cannot loop. Choose www if the preferred host is the one with www. Leave the host alone when another service already picks the host.
Redirect cheat sheet
This 301 redirect generator uses Redirect for a lone path rule. It switches to RewriteRule as soon as a condition is needed. That is also what you want from an htaccess generator when several rules share one file.
| Line | What it does |
|---|---|
Redirect 301 /old https://example.com/new | One permanent path change |
RewriteCond %{HTTPS} !=on | Only when the request is still HTTP |
RewriteRule ^ https://example.com%{REQUEST_URI} [R=301,L] | Send the same path to HTTPS |
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC] | Match the www host |
[R=301,L] | Permanent redirect, then stop |
[R=302,L] | Temporary redirect, then stop |
FAQ
What does this htaccess redirect generator make?
It writes the lines you paste into an .htaccess file. A single old path can point at a new URL, or you can paste many pairs. HTTPS, www, trailing slashes, file extensions, and a domain move can be added to the same file. The rules run in the browser and nothing you type is uploaded.
When should I use a 301 redirect generator instead of 302?
Use 301 when the move is permanent. Search engines treat a 301 as the new address. Use 302 only when the new address is temporary, such as a short campaign. This page defaults to 301.
How do I redirect HTTP to HTTPS in htaccess?
Turn on Force HTTPS and enter your domain. The file checks that the request is not already HTTPS, then sends it to https on the preferred host. If www is also selected, both changes happen in one redirect so visitors are not sent twice.
How do I redirect www to non-www in htaccess?
Choose Non-www as the host. Requests to www.yourdomain.com are sent to the bare domain. Choose www if you want the opposite. The host is checked so a request that is already correct is left alone.
Why does a simple path use Redirect 301, but HTTPS uses RewriteRule?
Redirect 301 is enough for one path on the same site, and it is easy to read. HTTPS, www, trailing slashes, and extension hiding need conditions, so those use RewriteEngine. When those are on, the path rules are RewriteRule lines too, because mixing Redirect and RewriteRule in one file can run in a surprising order.
What is a redirect loop or a chain?
A loop sends a URL back to itself. A chain sends it to a second URL that is also redirected. The page warns about both. The test box under the rules tells you which rule matches a URL you type, and whether that result would be redirected again.
Will this htaccess generator work on Hostinger?
Yes. Hostinger shared hosting uses Apache or LiteSpeed, and both read .htaccess. Upload the file to the site folder, or merge these lines into the file that is already there. Back up the current file first. Nginx hosting does not read .htaccess, so use the Nginx tab on those servers.
More from CoreCodify
This generator is free. CoreCodify also sells kits for moving a site and checking it before launch. Checkout stays on Gumroad.
- Browse the shopChecklists, calculators, and kits for people who build software.
- Website Migration SEO Kit: Redirect Map, Pre & Post-Launch Checklist, Tracker & Client ReportMove a client site to a new platform, URL pattern or domain without throwing away its search traffic: one process from the first crawl to the week-12 report, and a redirect map that marks its own faults.
- Next.js Technical SEO Checklist: 120-Point Audit for App Router Sites (+ Tracker, Report Template & Snippets)120 technical SEO checks written for Next.js 15 and 16 App Router sites, each with a test, the Next.js fix and a priority, plus a scoring workbook, a report template and 10 snippets.
- Website Pre-Launch QA Checklist: 79 Checks + Excel/Sheets Tracker for Web DesignersCatch the usual pre-launch misses on a client site - broken forms, leftover demo text, a forgotten noindex tag, missing redirects, a stuck mobile menu - with 79 checks, a live tracker and a handover pack.
- Cron expression generatorBuild a crontab or see when a schedule runs next.





