What is a 301 redirect?
A 301 is an HTTP status code that means moved permanently. When someone requests an old address, the server answers with a 301 and the new address, and the browser goes straight there. The visitor usually notices nothing except a different URL in the address bar.
The status code matters because it is a message to machines as well as people. A 301 tells search engines the old URL has been replaced for good, so they should index the new URL instead and transfer the signals the old page had earned. A 302, by contrast, says the move is temporary and the old URL should stay in the index. Choosing the wrong one during a site move is one of the most common ways to lose traffic overnight.
Every server speaks this language, but each one uses different syntax to say it. Apache uses rewrite rules in a .htaccess file. Nginx uses a return 301 line inside a server block. PHP sends a header. IIS uses XML rules in web.config. That is what this 301 redirect code generator handles: you supply plain URLs, choose where the code will run, and the tool writes syntax that is valid for that platform, with special characters escaped correctly.
When you need a 301 redirect
Any time a working URL stops being the right address, a permanent redirect belongs in its place. The usual situations:
- You renamed a page or changed its slug. Even a small edit, such as removing a year from a URL, breaks every existing link to it.
- You moved to a new domain. The single most important redirect job there is, because the whole site's history depends on it.
- You switched to HTTPS. Without redirects, the http and https versions both exist and compete.
- You merged two pages. Two thin articles combined into one strong guide means the weaker URL should point at the survivor.
- You changed your URL structure. Dropping
.phpor.html, or moving/blog/to/articles/, affects many URLs at once. - A product is discontinued but has a replacement. Send buyers to the replacement rather than an error page.
- You are consolidating duplicate versions. With and without www, with and without a trailing slash, uppercase and lowercase variants.
- A campaign URL needs to live on. Short vanity URLs printed on packaging or business cards should keep resolving years later.
The exception worth remembering: if a page is gone for good with no replacement, a 410 status is more honest than redirecting everyone to the homepage, which search engines treat as a soft 404.
How to use the BlogDada 301 redirect code generator
- Choose the tab that fits. Page URLs for individual pages, Whole domain when the entire site is moving to a new address.
- Enter your addresses. Old first, new second, separated by a comma, tab or two spaces. Full URLs and paths both work, so you can paste a two-column export from a spreadsheet or a crawl report without cleaning it up first.
- Pick your server. If you are on shared hosting or cPanel, it is almost certainly Apache. Pick Nginx for most VPS setups, IIS for Windows hosting, PHP if you cannot edit server config files, and the Cloudflare option if you manage redirects at the CDN.
- Generate the code. Each rule gets a short comment above it naming the URL it handles, so the file still makes sense to you months later.
- Copy or download. The download uses the right file name for the platform you picked, such as
htaccess.txt,redirects.conforweb.config. - Back up, upload, test. Save a copy of the file you are about to edit, add the new rules, then load one old URL in a private window and confirm it lands on the new page.
old-page.html also matches addresses you never intended. The generator escapes them for you, which removes the single most common cause of broken redirect rules.301 redirect code for every server
Apache (.htaccess)
Used by most shared hosting, cPanel hosts and LiteSpeed servers. The file sits in your site's root folder and takes effect immediately after saving.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^old-page/?$ /new-page [R=301,L]
</IfModule>
Nginx
Nginx ignores .htaccess entirely. Rules go inside the server block in your site configuration, and you must reload the service afterwards with nginx -s reload for them to apply.
location = /old-page { return 301 /new-page; }
PHP
Useful when you cannot edit server configuration, or when the redirect depends on logic in your application. The header must be sent before any output, and exit matters because without it the rest of the page still runs.
<?php
header('Location: /new-page', true, 301);
exit;
IIS (web.config)
Windows hosting uses XML rules. The URL Rewrite module must be installed, which it usually is on managed Windows hosts.
<rule name="301 redirect" stopProcessing="true">
<match url="^old-page/?$" />
<action type="Redirect" url="/new-page" redirectType="Permanent" />
</rule>
Cloudflare bulk redirects
If your DNS runs through Cloudflare, redirects can be handled at the edge before a request ever reaches your server. Bulk Redirects accepts a CSV list of source and target URLs with a status code, which is what the CSV option produces.
HTML and JavaScript
A meta refresh or a window.location.replace() call is a client-side redirect. The server still returns 200, the browser has to load the old page first, and search engines treat these far less reliably than a real 301. Use them only when you have no access to the server at all, and add a canonical tag pointing at the destination.
Redirects on WordPress, Shopify, Wix and Squarespace
Hosted platforms often do not let you touch server files, so they provide their own redirect panels instead.
- WordPress. You can edit .htaccess directly on Apache hosting, above the block marked
# BEGIN WordPress. A redirect plugin is the safer route for non-technical users and logs 404s as a bonus, though plugin redirects run after PHP loads and are slower than server-level rules. - Shopify. Redirects live under Online Store, then Navigation, then URL Redirects. Shopify only accepts paths on your own store, and always applies a 301.
- Wix. Found in the SEO settings under URL Redirect Manager, where you can add entries one at a time or import a CSV.
- Squarespace. Under Settings, then Developer Tools, then URL Mappings, using its own arrow syntax with a 301 flag.
- Managed WordPress hosts. Several strip or override custom .htaccess rules. If your rules keep vanishing, use the host's redirect panel instead of fighting the platform.
Whatever the interface, the underlying goal is identical: old URL in, new URL out, permanent status code.
301 vs 302, 307, 308 and 410
| Code | Meaning | Use it for |
|---|---|---|
| 301 | Moved permanently | Site moves, renamed pages, HTTPS migration, merged content. Signals transfer, browsers cache it. |
| 302 | Found, temporary | Short-lived changes such as a seasonal page or A/B test. The original URL stays indexed. |
| 307 | Temporary, method preserved | Forms and APIs where a POST must stay a POST. |
| 308 | Permanent, method preserved | Permanent API endpoint moves. Rare on content sites. |
| 410 | Gone | Content deliberately removed with no replacement. Drops from the index faster than a 404. |
Because browsers cache permanent redirects hard, a 301 pointed at the wrong destination is painful to undo for anyone who already visited. That is the one argument for testing with a 302 first during a complicated migration, then switching to 301 once you are sure the mapping is right.
What a 301 actually does to your SEO
Google has stated that 301 redirects pass ranking signals to the destination URL. In practice, that transfer depends on relevance: a redirect from an old review to the updated version of the same review is treated as a genuine move, while a redirect from a deleted page to an unrelated category page is treated as a soft 404 and passes nothing.
Timing is the other thing people misjudge. Visitors are redirected instantly, but search engines only learn about the change when they next crawl the old URL, which can take days for popular pages and weeks for forgotten ones. During that window you may see both URLs in results, or a temporary dip in impressions. Three things shorten it: submit an updated XML sitemap containing only the new URLs, update internal links so crawlers reach the new pages directly, and use the Change of Address tool in Google Search Console if you are moving domains.
Expect a short-term wobble even when everything is done correctly. Traffic usually returns to its previous level within a few weeks on a clean migration. If it has not recovered after a couple of months, the problem is normally mapping rather than the redirects themselves: pages sent somewhere loosely related instead of to a true equivalent.
Testing your 301 redirects
- Check the status code, not just the landing page. Open your browser's developer tools, look at the Network tab, load the old URL and confirm the first response says 301 rather than 302.
- Use a private window. Browsers cache 301s aggressively, so an old cached redirect can mask a rule you just corrected.
- Look for chains. Old URL to middle URL to final URL wastes crawl budget and adds latency. Point the first rule at the final destination.
- Try the awkward variants. With and without a trailing slash, with a query string, and in uppercase, to confirm your rule is neither too loose nor too strict.
- Crawl the site afterwards. Any SEO crawler will list redirect chains, loops and rules that now point at 404 pages, which is the fastest way to audit a large batch.
Mistakes to avoid
- Redirecting everything to the homepage. The laziest fix and the most costly, because it wipes out the relevance that made those pages rank.
- Using 302 for a permanent move. Common when a developer copies a snippet without checking the flag.
- Leaving internal links pointing at old URLs. The redirects hide the problem while slowing every click.
- Creating a loop. A rule that sends a URL to an address matching the same rule produces a "too many redirects" error and takes the page offline.
- Forgetting the canonical tag. If the new page still declares the old URL as canonical, you have sent two contradicting signals.
- Removing redirects too soon. Keep them at least a year after a migration, and indefinitely if the old URLs still earn traffic or hold backlinks.
- Not backing up. One bad line in .htaccess or web.config takes the whole site down, and a backup turns that into a thirty-second fix.
If you want a closer look at Apache-specific syntax, including folder and wildcard rules, our .htaccess redirect generator covers those in more depth.
Frequently asked questions
What is a 301 redirect?
A 301 is an HTTP status code that means a page has moved permanently. The server tells the browser and search engines that the old address is replaced by a new one, so visitors land on the new page and ranking signals transfer to it.
Which server type should I choose in the generator?
Most shared hosting, cPanel hosting and LiteSpeed servers use Apache, so choose the .htaccess option. Choose Nginx if your host or VPS runs Nginx, IIS web.config for Windows hosting, and PHP if you cannot edit server files. Your hosting dashboard or response headers will confirm which one you run.
Does a 301 redirect pass SEO value?
Yes. Google has said 301 redirects pass ranking signals to the destination URL. The new page still needs to be a close match for the old one, because redirecting unrelated content is treated as a soft 404.
Is a meta refresh the same as a 301 redirect?
No. A meta refresh or a JavaScript redirect happens in the browser after the page loads, so the server still returns a 200 status. Search engines handle them less reliably and more slowly. Use a server-side 301 whenever you can, and treat the HTML option as a last resort.
How long does a 301 redirect take to work in Google?
Visitors are redirected immediately. Google usually processes the change within a few days to a few weeks, depending on how often it crawls the old URL. Submitting an updated sitemap and keeping internal links pointed at the new URLs speeds this up.
Can I redirect an entire domain with one rule?
Yes. The whole domain option creates a single rule that sends every URL on the old domain to the same path on the new domain, so /about/ lands on /about/ rather than on the homepage.
How many 301 redirects can a site have?
There is no fixed limit, but thousands of individual rules in a .htaccess file slow every request down because Apache reads the file each time. Use folder or pattern rules where a pattern exists, and move very large lists into server configuration or a redirect service.
Generate your 301 redirect code
A permanent redirect is a small piece of code with a large job: it keeps your visitors, your links and your rankings attached to the pages that replaced the old ones. Paste your URL list above, choose your server, back up the file you are editing, and test one redirect before you walk away. Back to the generator.