301 Redirects Explained: .htaccess, Nginx and Laravel Examples
Every time a URL changes, visitors and search engines need to be sent to the new address. 301 redirects do that permanently, carrying users to the right page and telling search engines to transfer signals from the old URL to the new one. Getting them wrong leads to lost rankings, broken bookmarks and wasted crawl budget.
Redirect Status Codes in Plain Terms
- 301 Moved Permanently: the page has moved for good. Use for renamed URLs, merged content and domain moves.
- 308 Permanent Redirect: also permanent, but the request method is preserved. Google treats it like a 301.
- 302 Found and 307 Temporary Redirect: temporary moves, for example during short maintenance or A/B tests. Search engines keep the original URL indexed.
Google explains how it handles each type in its documentation on redirects and Google Search. The short version: if the move is permanent, use a permanent redirect.
When You Need a 301
- A page slug changes, for example after improving its title.
- Two articles are merged into one stronger page.
- A service is renamed or folded into another service page.
- You move from HTTP to HTTPS or between www and non-www.
- You migrate to a new domain or platform.
Do not redirect every deleted page to the homepage. If there is no close replacement, returning a 404 is more honest and Google treats mass homepage redirects as soft 404s anyway.
Apache: .htaccess Examples
For a single page, the simplest rule uses mod_alias:
Redirect 301 /old-page /new-page
For patterns, use mod_rewrite. This moves everything under an old folder to a new one:
RewriteEngine On
RewriteRule ^blog/(.*)$ /insights/$1 [R=301,L]
Force HTTPS and www in one hop to avoid chains:
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ https://www.example.com%{REQUEST_URI} [R=301,L]
Nginx Examples
Single page, using an exact-match location:
location = /old-page {
return 301 /new-page;
}
Whole domain move, preserving the path:
server {
server_name old-domain.com www.old-domain.com;
return 301 https://www.new-domain.com$request_uri;
}
Laravel Examples
Laravel's router has a dedicated helper for permanent redirects:
Route::permanentRedirect('/old-page', '/new-page');
Note that Route::redirect() returns a 302 by default unless you pass 301 as the third argument. For many redirects managed by editors, store them in a database table and apply them in middleware only when no route matches, so normal pages are never slowed down. Inside a controller, return a permanent redirect like this:
return redirect()->to('/new-page', 301);
Avoid Chains and Loops
A chain happens when URL A redirects to B, which redirects to C. Each hop adds delay and risks losing signals. When you update a redirect, point old URLs straight at the final destination. A loop, where A points to B and B back to A, makes the page unreachable. Crawl your site after every batch of changes to catch both.
Update Your Internal Links Too
Redirects are a safety net, not a substitute for correct links. After changing a URL, update menus, internal links, canonical tags and the XML sitemap to point to the new address directly. Our guides to internal linking and XML sitemaps cover this.
Redirects During a Redesign or Migration
Build a redirect map before launch: every old URL in one column, its best new match in the next, with a status column for testing. Test the map on staging, deploy it at launch, then monitor Search Console for 404s and indexing changes. The full process is in our SEO migration checklist for Laravel sites and our website redesign checklist.
How Long Should Redirects Stay?
Keep permanent redirects in place for at least a year, and longer for URLs that have external backlinks. Removing them early breaks links from other websites and loses the value they pass.
Need help planning redirects for a migration or redesign? Our web development team builds redirect handling and testing into every launch.
Frequently Asked Questions
Do 301 redirects lose SEO value?
Google has stated that permanent redirects do not cause a loss of PageRank. Problems usually come from chains, redirects to irrelevant pages or removing redirects too early.
Should I use 301 or 308?
Both are permanent and treated the same by Google. 301 is the most widely supported and is fine for normal page moves.
Can I redirect deleted pages to the homepage?
Only when the homepage genuinely replaces the content. Otherwise redirect to the closest relevant page or return a 404.
Comments
Comments appear after admin approval.