🔀 Htaccess Redirect Generator
By ToolNimba Web Dev Team · Updated 2026-06-19
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.
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.
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.
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.
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 |
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.
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.
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.