HTTP 301

From Wikipedia, the free encyclopedia
Jump to: navigation, search

The HTTP response status code 301 Moved Permanently is used for permanent URL redirection, meaning current links or records using the URL that the response is received for should be updated. The new URL should be provided in the Location field included with the response. RFC 2616 states that:

  • If a client has link-editing capabilities, it should update all references to the Request URL.
  • The response is cachable.
  • Unless the request method was HEAD, the entity should contain a small hypertext note with a hyperlink to the new URL(s).
  • If the 301 status code is received in response to a request of any type other than GET or HEAD, the client must ask the user before redirecting.


Client request:

GET /index.php HTTP/1.1

Server response:

HTTP/1.1 301 Moved Permanently

Here is an example using a htaccess file to redirect to a non www with a SSL attached to the domain.

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$$1 [R,L] 

Different methods of redirection[edit]

There are many ways through which anyone can redirect a url or website to any other url or website. For example :-

  • Redirecting using php
  • Redirecting by editing .htaccess file
  • Redirecting using cPanel
  • Redirecting using meta tags

Redirecting using php[edit]

Redirecting a url to any other page using php needs that the http header of the required file that needs to be redirected should be edited with header () function. Header () method is used to send a raw HTTP header as explained here about php redirect to url[1].

Search engines[edit]

Google recommends using a 301 redirect to change the URL of a page as it is shown in search engine results.[2]

See also[edit]


  1. ^ Detailed help on redirecting with php method -
  2. ^ 301 redirects - Webmaster Tools Help -