What is a .htaccess redirect?
A redirect is an instruction that sends anyone who requests one address to a different address instead. When you rename a page, move a blog to a new folder, switch domains or move from http to https, the old addresses stop working. A redirect keeps them working by passing every visitor, and every search engine crawler, on to the right destination.
On Apache servers, those instructions usually live in a file called .htaccess. It is a plain text configuration file that sits in a folder on your website and changes how the server behaves for that folder and everything below it. The leading dot marks it as a hidden file, which is why many people never notice it in their hosting file manager until they go looking.
The tricky part is the syntax. Apache redirect rules use regular expressions and flags such as [R=301,L], and a single wrong character can take a site offline with a 500 error. That is the problem this .htaccess redirect generator solves: you describe the move in plain URLs, and the tool writes the escaped, valid rule for you.
The tool covers the four situations that come up most often: individual pages moving to new addresses, an entire folder moving, pattern-based moves such as dropping .php or .html from every URL, and site-wide canonical rules for HTTPS, www and domain changes. Everything runs inside your browser, so nothing you type is uploaded anywhere.
Why redirects matter for SEO
Redirects are not just a convenience for visitors. They protect the value you have already earned.
- They preserve ranking signals. Google has confirmed that permanent redirects pass ranking signals from the old URL to the new one. Without a redirect, links pointing at the old page count for nothing.
- They stop 404 errors. Every deleted or renamed page without a redirect becomes a dead end for visitors arriving from search results, social posts, emails and other websites.
- They prevent duplicate content. If your site loads at both www and non-www, and at both http and https, search engines can see four versions of every page. Canonical redirects collapse them into one.
- They save crawl budget. Crawlers that keep hitting broken or duplicate URLs spend less time on the pages you actually want indexed.
- They keep conversions. Old product URLs sitting in someone's bookmarks or in a printed brochure still reach a live page instead of an error.
Redirects are not a ranking boost on their own. They are damage control: done well, you keep what you had, and the move becomes invisible to search engines within a few weeks.
How to use the BlogDada .htaccess redirect generator
- Pick the tab that matches your move. Use Single URLs for individual pages, Domain & HTTPS for site-wide rules, Folders when a whole section moves, and Wildcards when many URLs change in the same pattern.
- Enter your addresses. Put the old address first and the new one second, separated by a comma, a tab, or two or more spaces. You can paste straight from a spreadsheet of old and new URLs. Paths such as
/old-pageand full addresses such ashttps://example.com/new-page/both work. - Choose the redirect type. 301 is right for almost every permanent move. The next section explains when the others apply.
- Generate the code. Each rule appears with a short comment above it showing which URL it handles, so the file stays readable months later.
- Copy or download. Use Copy code to paste into an existing file, or Download .htaccess if you are starting fresh.
- Back up, then upload. Download your current .htaccess before changing anything, add the new rules near the top of the file, save, and test a few URLs straight away.
old-page.html matches any character, so the rule fires on URLs you never intended.301, 302, 307, 308 and 410 explained
The status code tells browsers and search engines how to treat the move. Choosing the wrong one is one of the most expensive mistakes in a site migration.
| Code | Meaning | When to use it |
|---|---|---|
| 301 | Moved permanently | The standard choice. Site moves, renamed pages, merged content, http to https, www canonicalisation. Ranking signals pass to the new URL and browsers cache the redirect. |
| 302 | Found, temporary | Short-term changes such as a seasonal offer page or maintenance detour. The original URL stays indexed. |
| 307 | Temporary, method preserved | Like a 302, but a POST request stays a POST. Useful for forms and APIs. |
| 308 | Permanent, method preserved | Like a 301, with the request method preserved. Rare on normal websites but correct for API endpoints. |
| 410 | Gone | Not a redirect. It says the page was deliberately removed and is not coming back, which gets it dropped from the index faster than a 404. |
A practical rule of thumb: if the content still exists somewhere, use 301 and point at the closest match. If the content is gone with no replacement, a 410 is more honest than redirecting everyone to the homepage. The generator writes 410 rules when you type gone as the destination.
Where to put the code in your .htaccess file
1. Find the file
The main .htaccess file sits in the root folder of your website, usually named public_html, www or httpdocs. In cPanel File Manager, open Settings in the top-right corner and tick Show hidden files, otherwise the file stays invisible. In an FTP client such as FileZilla, enable forced showing of hidden files in the server menu.
2. Back it up
Download the existing file to your computer before editing, or copy it in place as htaccess-backup.txt. If a new rule breaks the site, restoring that copy fixes it in seconds. This step is not optional; a broken .htaccess takes down every page at once.
3. Paste the rules in the right place
Apache reads the file from the top down, and the L flag stops processing once a rule matches. So the order of rules is the order of priority. Put site-wide rules such as HTTPS and www first, then specific page redirects, and keep everything above the block your CMS manages. On WordPress, that block is marked like this:
# Your redirects go above this line
# BEGIN WordPress
...WordPress rules...
# END WordPress
Never edit inside the WordPress block, because the CMS rewrites it whenever permalinks are saved and your changes would disappear.
4. Save and test immediately
Upload the file, then load your homepage and one redirected URL in a private browsing window. Testing right away means that if something is wrong, you know exactly which change caused it.
Redirect types this tool creates
Single page redirect
The most common case: one page has moved to a new address.
RewriteEngine On
RewriteRule ^old\-page/?$ /new-page [R=301,L]
Force HTTPS
Sends every insecure request to the secure version of the same page, keeping the path intact.
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
www and non-www
Pick one version and stick to it forever. Which one you choose does not affect rankings; consistency does.
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [R=301,L]
Whole domain move
Every URL on the old domain lands on the same path on the new one, which is what search engines expect during a migration.
RewriteCond %{HTTP_HOST} ^(www\.)?olddomain\.com$ [NC]
RewriteRule ^(.*)$ https://newdomain.com/$1 [R=301,L]
Folder redirect
Moves a section and everything inside it, so /blog/post-name/ becomes /articles/post-name/.
RewriteRule ^blog/?$ /articles/ [R=301,L]
RewriteRule ^blog/(.*)$ /articles/$1 [R=301,L]
Wildcard pattern redirect
Handles bulk changes such as dropping a file extension across hundreds of URLs, without writing one rule per page.
RewriteRule ^product/(.*)\.html$ /shop/$1 [R=301,L]
Testing your redirects
Never assume a rule works because the page loads. A redirect can land on the right page with the wrong status code, which looks fine to visitors but sends the wrong message to search engines.
- Check the status code, not just the destination. Use your browser's developer tools, open the Network tab, load the old URL and look at the status of the first request. It should read 301, not 302.
- Test in a private window. Browsers cache permanent redirects aggressively, so an old cached 301 can hide a rule you just fixed.
- Watch for chains. Old URL to second URL to final URL is a chain. Each hop adds delay, so rewrite the first rule to point straight at the final destination.
- Test a few edge cases. Try the URL with and without a trailing slash, with a query string, and in uppercase, to confirm the rule is neither too narrow nor too greedy.
- Re-crawl the site. After a large batch, crawl your site with any SEO crawler and check the redirect report for loops, chains and rules that now point at 404 pages.
.htaccess redirect best practices
- Redirect to the closest matching page. Sending every removed page to the homepage is treated as a soft 404 and wastes the signals you were trying to keep.
- Keep rules in a sensible order. Site-wide canonical rules first, specific page rules after, because the first matching rule with an
Lflag wins. - Avoid redirect chains and loops. Update old rules instead of stacking new ones on top when a page moves twice.
- Update your internal links. Redirects are a safety net for outside traffic, not a substitute for fixing menus, in-content links and sitemaps.
- Keep the file lean. Apache reads .htaccess on every request. Thousands of individual rules slow a site down, so use a wildcard or folder rule where a pattern exists.
- Comment your rules. A line explaining why a redirect exists saves confusion a year later. The generator adds these automatically.
- Leave redirects in place. A year is the usual minimum after a migration, and longer if the old URLs still earn traffic or hold backlinks.
Common mistakes and how to fix errors
500 internal server error
Almost always a syntax problem, a rule placed outside its <IfModule> block, or a missing RewriteEngine On line. Restore your backup to bring the site back, then add rules in small batches until you find the one that breaks it. If the error persists with correct syntax, ask your host to confirm mod_rewrite is enabled.
Redirect loop, or too many redirects
This happens when a rule sends a URL to an address that matches the same rule again, for example redirecting /page to /page/ while another rule strips trailing slashes. Make the pattern more specific, or add a condition so the rule skips requests that already match the destination.
RewriteCond %{REQUEST_URI} !^/new-page
RewriteRule ^old-page$ /new-page [R=301,L]
Nothing happens at all
Check that the file is named exactly .htaccess with no extension. Windows and some editors quietly save it as .htaccess.txt, which the server ignores. Also confirm it is in the correct folder, and that your host allows overrides.
The rule catches the wrong URLs
Unescaped regex characters are the usual cause. A dot matches any character, so page.html also matches pageXhtml. The generator escapes these for you.
The redirect drops the query string
By default Apache appends the original query string to the new URL. To drop it, end the destination with a question mark. To keep it explicitly, add the QSA flag.
Plugins, Nginx and LiteSpeed
If you run WordPress and only need a handful of redirects, a redirect plugin is a reasonable choice: it is safer for non-technical users and logs 404s so you can spot broken URLs. The trade-off is speed, because plugin redirects run after PHP and WordPress load, while .htaccess rules are handled by the web server before any of that. For large-scale moves, the server-level approach is noticeably faster and lighter.
Server software matters too. The .htaccess file is an Apache feature. LiteSpeed and OpenLiteSpeed read it as well, so the generated code works on most shared hosting and on many managed WordPress hosts. Nginx does not read .htaccess at all, and rules must go in the server configuration, which usually means asking your host or editing the config yourself. If you are unsure which server you run, your hosting dashboard or a quick check of the response headers will tell you.
Some managed WordPress hosts also strip or override custom .htaccess rules. If your rules keep disappearing, check your host's documentation before assuming the syntax is wrong, and use their redirect panel instead where one exists.
Frequently asked questions
Is this .htaccess redirect generator free?
Yes. The tool is free, needs no sign-up and has no limit on the number of redirect rules you create. Everything runs in your browser, so your URLs are never sent to a server.
Where do I paste the generated .htaccess code?
Paste it into the .htaccess file in the root folder of your website, above any existing WordPress or CMS rules. Always download a copy of the original file first so you can restore it if something breaks.
What is the difference between a 301 and a 302 redirect?
A 301 is permanent and tells search engines the page has moved for good, so ranking signals pass to the new URL. A 302 is temporary and keeps the original URL indexed. Use 301 for site moves and deleted pages, and 302 only for short-term changes such as a seasonal landing page.
Why is my redirect showing a 500 internal server error?
A 500 error after editing .htaccess almost always means a syntax problem, a rule placed outside its IfModule block, or mod_rewrite not being enabled on the server. Restore your backup, add rules back a few at a time, and ask your host to confirm mod_rewrite is active.
Do .htaccess redirects work on Nginx servers?
No. The .htaccess file is an Apache feature. Nginx ignores it and needs rewrite rules in its own server configuration. LiteSpeed and OpenLiteSpeed do read .htaccess, so the generated code works there.
Will a 301 redirect pass my SEO rankings?
Google has said that 301 redirects pass ranking signals to the new URL. Rankings still depend on the new page being relevant to the old one, so redirect to the closest matching page rather than sending everything to the homepage.
How long should I keep a redirect in place?
Keep redirects for at least a year after a site move, and longer if the old URLs still receive traffic or hold backlinks. Many sites keep permanent redirects indefinitely because removing them turns working links into 404 errors.
Generate your redirect rules
Whether you are moving one page or an entire domain, the safest redirect is the one you did not have to write by hand. Fill in the old and new addresses above, generate the code, back up your file, paste the rules in and test the result. Your visitors keep landing on live pages, and the links you have earned keep working. Back to the generator.