← Back to Chapters

301 Moved Permanently

? 301 Moved Permanently

? Quick Overview

301 Moved Permanently is an HTTP status code that tells the browser and search engines that a requested resource has been permanently moved to a new URL. All future requests should use the new URL instead of the old one.

? Key Concepts

  • Indicates a permanent URL change
  • Browsers automatically redirect to the new URL
  • Search engines transfer SEO value to the new address
  • Used in website restructuring and HTTPS migrations

? Syntax / Theory

When a client requests a URL that has been permanently moved, the server responds with:

  • Status code: 301
  • Response header: Location: new-url

? Code Example(s)

? View Code Example
// Apache .htaccess permanent redirect
Redirect 301 /old-page.html https://example.com/new-page.html
? View Code Example
// PHP 301 redirect using header()
header("Location: https://example.com/new-page", true, 301);
exit();

? Live Output / Explanation

When a user visits /old-page.html, the browser receives a 301 response and automatically loads /new-page.html. Search engines update their index to the new URL.

?️ Interactive Simulator

Click "Go" to watch the browser process a 301 redirect.

?
 
 

?️ Interactive Flow Diagram

Browser Request Server (301) New URL

? Use Cases

  • Migrating from HTTP to HTTPS
  • Changing domain names
  • Removing or renaming pages
  • Consolidating duplicate content

✅ Tips & Best Practices

  • Use 301 only for permanent redirects
  • Always test redirects after deployment
  • Update internal links to the new URL
  • Avoid redirect chains

? Try It Yourself

  • Create a 301 redirect in a local Apache server
  • Test the redirect using browser dev tools
  • Compare 301 vs 302 behavior
  • Observe SEO impact in search console