Urgent.News

What's breaking now, across thousands of outlets.

Tech

Bulk 301 Redirects in .htaccess: A Step-by-Step Guide

Originally published on the MatrixInn Solutions blog . When you change URLs — a redesign, a new CMS, merging blog posts, moving to a new domain — every old URL that isn't redirected turns into a 404. Visitors hit a dead end, and the ranking signals that page earned stay stuck on a URL that no longer exists. A 301 redirect tells browsers and search engines the page has moved permanently and passes…

When websites undergo a redesign, move to a new CMS, or merge blog posts, old URLs become obsolete, resulting in 404 errors for visitors and a loss of ranking signals. A 301 redirect informs browsers and search engines that the page has permanently moved, transferring those signals to the new address. While redirecting a single page is straightforward, managing 200 redirects can be tricky. Here's a step-by-step guide for any size migration.

First, create a redirect map in a spreadsheet with two columns: old path and new URL. Each row represents a page. The old path can be sourced from your previous sitemap.xml, Google Search Console's Pages report, or a site crawl using a tool like Screaming Frog. Prioritize URLs with actual traffic. Map every old URL to its closest equivalent, rather than the homepage, as Google treats mass redirects to the homepage as soft 404s.

Next, generate the redirect rules. For straightforward one-to-one moves, use Apache's mod_alias: Redirect 301 /services/web-design.html https://example.com/services/web-design. If using mod_rewrite (common in WordPress or PHP frameworks), include all rules in the same module to prevent conflicts. The patterns should end with $ and include anchors (^) to prevent unintended matches. Use a free online .htaccess redirect generator to automate the process and avoid errors.

Place the rules at the top of your .htaccess file, after the RewriteEngine On directive but before any catch-all rules. Ensure more specific paths are listed above broader patterns to avoid conflicts. Avoid common mistakes like redirect chains, loops, and using 302 instead of 301. Test the redirects using curl or a script, then verify the new sitemap in Google Search Console and monitor the Pages > Not found (404) report for any missed redirects.

Redirects should remain in place for at least a year, preferably permanently, to maintain the integrity of traffic and backlinks.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

More from Tuesday 29 September →