When a page moves, the old address should not die: it should redirect, sending visitors and search ranking to the new address. On Apache servers that means .htaccess rules, and the syntax is unforgiving: a missing flag, a wrong pattern anchor, or a redirect loop can take a site down or trap visitors in circles. This generator writes correct rules from your choices: a single page redirect with 301 or 302 status, a whole-site www to non-www canonicalisation, or an HTTP to HTTPS upgrade. Paste the output into .htaccess, test it, and the move is handled cleanly.
Quick Answer: Choose the redirect type, enter the old and new paths, and click Build Rules.
Free Online Tool
.htaccess Redirect Generator
Build Apache 301/302 redirect rules, including www/non-www and HTTP to HTTPS rules.
How to Use the .htaccess Redirect Generator
- Choose Single redirect for one page, or a site-wide option.
- For a single redirect, enter the old path and the new path.
- Choose 301 for a permanent move or 302 for temporary.
- Click Build Rules.
- Copy the output into your .htaccess file.
- Test the old URL in a browser and confirm it lands on the new one.
Key Features
- Generates single-page 301 and 302 RewriteRules.
- Builds www to non-www and non-www to www rules.
- Builds HTTP to HTTPS upgrade rules.
- Includes RewriteEngine On where needed.
- Anchors patterns so partial matches do not redirect wrongly.
- Runs entirely in the browser; nothing is deployed automatically.
What the Result Means
A 301 tells browsers and search engines the move is permanent, so ranking and bookmarks transfer; a 302 says temporary, so the old address keeps its standing. The RewriteRule pattern is matched against the path without a leading slash, which is why the generated pattern starts with ^ and your old path should not start with a slash. The flags at the end matter: R=301 sets the status and L stops further rule processing for that request. A site-wide rule uses a condition on the host or scheme, so it applies to every page without listing them.
Worked Example
A shop renames its sale page from old-page to new-page permanently. Entering old-page and /new-page with type 301 produces: RewriteEngine On followed by RewriteRule ^old-page/?$ /new-page [R=301,L]. Visitors to the old address arrive at the new page, search engines transfer the ranking, and bookmarks keep working. Search engines treat the 301 as a signal to transfer ranking to the new address, which is why the permanent status matters so much for a renamed page. If the same shop later moves the whole site to HTTPS, the HTTP to HTTPS rule upgrades every address without touching the individual page rules.
Best Practices and Tips
- Use 301 for permanent moves such as redesigns and domain changes.
- Use 302 only when the old address will genuinely return.
- Test redirects with a fresh browser session to avoid cached results fooling you.
- Avoid redirect chains: point old addresses straight at the final destination.
- Keep a list of redirects you deploy, so future moves do not create loops.
Common Mistakes to Avoid
- Using 302 for a permanent move and losing ranking transfer.
- Creating a redirect loop by pointing two pages at each other.
- Forgetting RewriteEngine On at the top of the file.
- Redirecting everything to the homepage instead of the matching new page.
Frequently Asked Questions
What is the difference between 301 and 302?
301 is permanent and transfers ranking; 302 is temporary and keeps the old URL standing.
Where does the output go?
Into the .htaccess file in your site root, or the relevant directory, on an Apache server.
Do I need the leading slash in the old path?
No. The pattern matches without it, and this generator strips it if you include it.
Can I redirect a whole domain?
Yes, with the site-wide options, which use conditions on the host instead of listing pages.
