How to Generate .htaccess 301 Redirects Step by Step
To generate .htaccess redirects, list each old path and the new path it should point to, choose 301 (permanent) or 302 (temporary), optionally enable Force HTTPS and a www preference, then copy or download the ready-to-paste rules from the ByteTools Htaccess Redirect Generator. You get valid Apache mod_rewrite syntax without hand-writing a single line.
This guide walks through the full process — from adding your first redirect row to placing the file on your server and confirming it works.
What the generator produces
The tool turns a simple table of old-to-new URL pairs into an Apache .htaccess file. Alongside per-URL redirects it can add the two site-wide canonicalization rules SEOs use most: forcing every request onto HTTPS, and forcing a single hostname (either www or non-www). Everything is assembled live in your browser and downloads as a real .htaccess file — nothing is uploaded to a server.
Step-by-step walkthrough
- Add a redirect row. Enter the old path (for example
/old-page) and the new path or full URL it should point to. - Repeat for every URL. Add as many rows as you need — one per redirect you're setting up.
- Choose the redirect type. Pick 301 for permanent moves so search engines transfer ranking signals, or 302 for temporary changes you'll reverse later.
- Enable canonicalization (optional). Toggle Force HTTPS to push every visitor to the secure version, and choose Force www or Force non-www to enforce one hostname.
- Copy or download. Grab the generated rules with one click, or download the finished
.htaccessfile. - Deploy and test. Upload the file to your site's root directory and visit an old URL in your browser to confirm it lands on the new one.
Where to put the file and how to test
The .htaccess file belongs in your site's root directory — the same folder as your main index file. The rules apply to that folder and everything below it. The name must be exactly .htaccess, with the leading dot and no extension. After uploading, open an old URL directly; a correct 301 will send you to the destination and browser dev tools will show a 301 Moved Permanently status.
| Goal | What to set |
|---|---|
| Permanently move a page | Add a row, choose 301 |
| Temporary A/B or maintenance redirect | Add a row, choose 302 |
| Force secure connections | Enable Force HTTPS |
| One canonical hostname | Choose Force www or non-www |
Why generate it in the browser
The rules are assembled entirely client-side, so your URL list and site structure never leave your machine — useful when you're mapping out a migration that isn't public yet. It's free, requires no account, and works offline once loaded. You still get standard, portable mod_rewrite output that any Apache host will read.
Try the Htaccess Redirect Generator — free and 100% in your browser.
FAQ
Do I need to know mod_rewrite to use this?
No. You fill in old and new paths in plain form fields and the tool writes the RewriteRule and RewriteCond syntax for you. Knowing the basics helps you review the output, but it isn't required to generate working rules.
Does the generated file work on Nginx?
No — .htaccess and mod_rewrite are Apache features. Nginx uses a different configuration format. This tool targets Apache and Apache-compatible hosting (including shared hosting that uses Apache).
Can I mix 301 and 302 redirects in one file?
Yes. You can choose the status per configuration, so a single generated file can contain permanent 301s and temporary 302s together.
What happens if I don't add a leading slash to a path?
Paths are matched relative to your site root, so it's safest to enter them as the tool expects (for example /old-page). Review the generated rule and test in a browser to confirm the match behaves as intended.
Related free tools
- Robots.txt Generator — control what crawlers can access.
- Canonical Tag Generator — signal your preferred URL at the page level.
- XML Sitemap Generator — help search engines find your pages.
- Meta Robots Generator — set indexing directives per page.
Built by ByteVancer
ByteTools is a free product of ByteVancer, a software and web development studio building web apps, SaaS and custom software. If a site migration is part of a bigger project, explore how ByteVancer can plan and execute it cleanly.
Recommended reading
Htaccess Redirect Best Practices and Mistakes to Avoid
Avoid redirect chains, loops and lost link equity. Best practices for .htaccess 301 redirects, HTTPS and www canonicalization, plus troubleshooting tips.
Htaccess Redirect Use Cases: Migrations and Fixes
Real scenarios for .htaccess redirects: site migrations, HTTPS moves, www canonicalization, broken-link fixes and URL restructures, with worked examples.
Yes or No Generator: Real Use Cases and Examples
From beating decision paralysis to games and classrooms, see real use cases and examples for a random yes or no generator.
Yes or No Generator Tips and Common Mistakes
Get better decisions from a random yes or no generator. Pro tips, when to add Maybe, and the common mistakes to avoid when picking answers.