๐ Htaccess Redirect Generator
By Shihab Mia ยท Updated 2026-07-29
Use 301 for moves that are permanent so search engines pass ranking to the new URL. Use 302 only while a change is temporary.
Picks one canonical host and redirects the other version to it.
Bare domain, no https:// and no path. Needed for the domain and HTTPS rules.
Sends every plain http request to the secure https version.
Old path starts with a slash, for example /old-page. The new target can be a path like /new-page or a full URL like https://example.com/new-page.
Add at least one redirect or a domain rule, then paste the result into the .htaccess file at your site root.
This htaccess redirect generator builds the Apache directives you need to send old URLs to new ones, without hand-writing regex. Add one or more rows of old path to new URL, pick a 301 (permanent) or 302 (temporary) redirect, and optionally force a single www or non-www domain and push every request to HTTPS. The tool prints clean, ready-to-paste rules in two flavours, the simple Redirect directive and the more flexible RewriteRule, with a one-click copy button. Everything runs in your browser, so nothing you type ever leaves your device.
What is the Htaccess Redirect Generator?
A redirect tells a browser, and a search engine crawler, that a page now lives at a different address. On an Apache server the rules live in a plain text file named .htaccess, placed in the folder you want them to apply to (usually the site root). When a visitor or crawler asks for the old URL, Apache answers with a redirect status code and the new location, and the browser quietly follows it. Done correctly, visitors never see a broken link and search engines move their record of the page to the new URL.
The status code matters more than people expect. A 301 is a permanent redirect: it tells search engines the move is final, so they should index the new URL and pass most of the old page ranking signals to it. A 302 (and the related 307) is a temporary redirect: search engines keep the old URL indexed because you have signalled the change is short term, for example during maintenance or an A/B test. Using a 302 for a permanent move is one of the most common SEO mistakes, because the new page may struggle to inherit the old page authority.
Apache gives you two main ways to write a redirect. The Redirect directive (from mod_alias) is the simplest: Redirect 301 /old-page /new-page. It is perfect for straightforward one-to-one moves. The RewriteRule directive (from mod_rewrite) is more powerful and is what you need for pattern matching, forcing HTTPS, or choosing a canonical www or non-www host. RewriteRule needs RewriteEngine On to be present once near the top of the file. This generator can output either style, and it adds the RewriteEngine On line and helpful comments for you.
Rule order inside .htaccess matters, because Apache stops at the first RewriteRule that matches unless you use flags to keep going. Put narrow, specific rules (a single old path) above broad, generic ones (a whole folder or a www/HTTPS rule that touches every request), otherwise a general rule can catch a request before your specific redirect ever runs. It also helps to group all your canonical host and HTTPS rules together near the top of the file, then list one-to-one page redirects below them, so the logic reads top to bottom the way Apache actually processes it.
Before you rely on a redirect in production, test it safely. Browsers and some proxies cache 301 responses aggressively, so if a rule looks wrong after you edit it, a hard refresh or an incognito window is often needed to see the real, current behaviour rather than a cached one. Command line tools such as curl -I https://example.com/old-page show the exact status code and Location header Apache is sending, which is the fastest way to confirm a rule is firing before you publish it site-wide. It is also worth starting with 302 while you validate a large batch of new rewrites, then flipping the confirmed ones to 301 once you are confident nothing loops or 404s.
When to use it
- Moving or renaming pages after a site redesign and pointing the old URLs at the new ones so links and rankings survive.
- Consolidating a site onto one canonical host by forcing either www or non-www, so search engines do not see two versions.
- Forcing every visitor onto HTTPS after installing an SSL certificate, so no one lands on the insecure http version.
- Cleaning up legacy URLs in bulk by pasting many old to new pairs at once instead of editing .htaccess by hand.
- Migrating a blog, catalog, or knowledge base to a new URL structure after a CMS or platform change.
- Retiring an old domain and sending its entire traffic, path for path, to a replacement domain.
How to use the Htaccess Redirect Generator
- Choose the redirect type: 301 for a permanent move, 302 for a temporary one.
- Add a row for each old path and its new target. The old path starts with a slash, the target can be a path or a full URL.
- Optionally enter your domain and pick a www or non-www rule, and turn on Force HTTPS, to add canonical rules.
- Pick the Redirect or RewriteRule style, then copy the generated block into the .htaccess file at your site root.
- Test each rule with a hard refresh, an incognito window, or curl -I before you consider the migration finished.
Formula & method
Worked examples
You renamed /about-us to /about and want a permanent move using the simple Redirect directive.
- Set redirect type to 301 (permanent).
- Add one row: old path /about-us, new target /about.
- Leave the RewriteRule box unticked to use the Redirect directive.
- The tool outputs: Redirect 301 /about-us /about
Result: Redirect 301 /about-us /about
You want every request forced to the non-www HTTPS version of example.com.
- Enter domain example.com and set Force HTTPS to yes.
- Set canonical domain rule to Force non-www.
- Keep RewriteEngine On ticked, since these rules use mod_rewrite.
- The tool emits an HTTPS RewriteCond and rule plus a www to non-www rule, both as 301.
Result: RewriteEngine On, an HTTPS off condition redirecting to https://example.com/$1, and a www to non-www 301 rule.
You are retiring old-store.com and want the whole site, path for path, to land on new-store.com.
- Enter the old domain in the RewriteCond so it only matches traffic still hitting old-store.com.
- Set the target to https://new-store.com and select 301 permanent.
- Use a pattern rule so the captured path ($1) is appended to the new domain instead of typing every page.
- The tool emits a RewriteCond matching the old host and a RewriteRule that forwards the full path with query string preserved.
Result: RewriteCond %{HTTP_HOST} ^(www\.)?old-store\.com$ [NC] followed by RewriteRule ^(.*)$ https://new-store.com/$1 [R=301,L,QSA]
Common HTTP redirect status codes and when to use them
| Code | Meaning | Use it for |
|---|---|---|
| 301 | Moved permanently | A page that has permanently moved, passes ranking signals |
| 302 | Found (temporary) | A short-term move, keeps the old URL indexed |
| 307 | Temporary redirect | Temporary move that must keep the request method |
| 308 | Permanent redirect | Permanent move that must keep the request method |
Apache directive cheat sheet used by this generator
| Directive | Plain-language meaning |
|---|---|
| RewriteEngine On | Turns on the mod_rewrite engine, required before any RewriteRule |
| Redirect 301 /old /new | Simple permanent redirect from one path to another |
| RewriteCond | A condition that must be true for the next RewriteRule to fire |
| RewriteRule ^old$ /new [R=301,L] | Match a path, redirect with a 301, and stop processing |
| [R=301,L] | Flags: R sets the redirect code, L means last rule |
| [NC] | Flag: makes the match case-insensitive |
| [QSA] | Flag: keeps the original query string on the new URL |
The four www and HTTPS combinations, and the rule each one needs
| Current URL | Wanted canonical URL | Rule needed |
|---|---|---|
| http://example.com | https://example.com | Force HTTPS condition and rule |
| http://www.example.com | https://example.com | Force HTTPS plus force non-www |
| https://www.example.com | https://example.com | Force non-www only, HTTPS already on |
| http://example.com | https://www.example.com | Force HTTPS plus force www |
Common mistakes to avoid
- Using a 302 for a permanent move. A 302 tells search engines the change is temporary, so they may keep the old URL indexed and not pass ranking to the new page. For a permanent move always use 301.
- Forgetting RewriteEngine On. Every RewriteRule needs the mod_rewrite engine switched on. If RewriteEngine On is missing, the rewrite rules are ignored and your HTTPS or www redirects silently do nothing.
- Creating a redirect loop. Redirecting /a to /b and /b back to /a, or forcing HTTPS without a condition that excludes already-secure requests, sends the browser in circles until it gives up. Always add the right RewriteCond so a rule only fires when needed.
- Mixing relative and absolute targets carelessly. A Redirect directive target should be a path like /new-page or a full URL like https://example.com/new-page. A bare word with no leading slash can resolve in unexpected ways, so be explicit.
- Putting .htaccess in the wrong folder. Rules only apply from the folder the .htaccess file sits in and its subfolders. For site-wide redirects the file belongs in the document root, not in a subdirectory.
- Trusting the browser after editing a rule. Browsers cache 301 responses hard, so a fixed or corrected rule can still look broken until you hard refresh, clear the cache, or test in an incognito window. Use curl -I to see the real, current status code instead of guessing from the browser.
Glossary
- .htaccess
- A per-directory Apache configuration file that lets you set rules like redirects without editing the main server config.
- 301 redirect
- A permanent redirect status code that tells browsers and search engines a page has moved for good.
- 302 redirect
- A temporary redirect status code that keeps the original URL as the indexed one.
- mod_rewrite
- The Apache module that powers RewriteRule, used for pattern-based redirects and rewrites.
- Canonical host
- The single preferred version of your domain, either www or non-www, that all traffic should use.
- RewriteCond
- A condition line that must be met for the RewriteRule directly below it to take effect.
- RewriteBase
- A directive that sets the base URL path mod_rewrite uses when a rule produces a relative substitution, useful when .htaccess lives in a subfolder.
- 500 Internal Server Error
- The error Apache shows when a rule has broken syntax or an unsupported directive, usually meaning a typo in the .htaccess file itself.
Frequently asked questions
What is the difference between a 301 and a 302 redirect?
A 301 is a permanent redirect: it tells search engines the page has moved for good, so they index the new URL and pass most ranking signals to it. A 302 is temporary, so search engines keep the old URL indexed. Use 301 for permanent moves and 302 only while a change is genuinely short term.
Where do I put the generated htaccess rules?
Paste them into the .htaccess file in your site document root, which is usually the public_html or www folder. If the file does not exist yet, create a plain text file named exactly .htaccess (with the leading dot and no extension) and add the rules there.
Should I use the Redirect directive or RewriteRule?
For simple one-to-one moves the Redirect directive is shorter and clear. For forcing HTTPS, choosing a www or non-www host, or any pattern matching, use the RewriteRule variant. This generator can output either, and RewriteRule needs RewriteEngine On set once near the top of the file.
How do I force my whole site to HTTPS in htaccess?
Enter your domain and set Force HTTPS to yes. The tool adds a RewriteCond that checks whether the connection is already secure and a RewriteRule that sends every plain http request to the matching https URL with a 301. Make sure you have a valid SSL certificate installed first.
Will a 301 redirect hurt my SEO?
A correctly set 301 protects SEO rather than harming it. It passes the bulk of the old page authority to the new URL and stops visitors hitting dead links. Problems come from using the wrong code, chaining many redirects together, or creating loops, all of which this generator helps you avoid.
Does this tool send my URLs to a server?
No. The generator runs entirely in your browser using plain JavaScript. Your domain, paths and targets are never uploaded anywhere, so you can safely use it for private or staging sites.
How do I redirect an entire old domain to a new domain?
Use a RewriteCond that matches the old host name, then a RewriteRule with a capture group like ^(.*)$ pointing at https://new-domain.com/$1 with the QSA flag so query strings survive. This forwards every path on the old domain to the same path on the new one instead of you writing a rule per page.
How do I test htaccess redirects before I trust them?
Run curl -I https://example.com/old-page from a terminal and check the HTTP status code and Location header it returns. This shows the real rule Apache is applying, without the browser caching that can make a fixed or broken rule look unchanged for a while.
Why does my .htaccess file cause a 500 Internal Server Error?
A 500 error almost always means a syntax mistake in the file, a directive your host does not allow, or a module like mod_rewrite that is not enabled on that server. Remove the last rule you added and reload the page, if the error disappears the problem is in that rule.
Does the order of rules in .htaccess matter?
Yes. Apache processes RewriteRule lines top to bottom and stops at the first match unless you chain flags. Put specific, one-off page redirects above broad rules like www or HTTPS forcing, otherwise a general rule can intercept a request before your specific redirect gets a chance to run.