301

Moved Permanently

Official
the URL has changed, for further requests this should be used

Specification of the HTTP status code 301

The 301 Moved Permanently status code indicates that the target resource has been assigned a new permanent URI and any future references to this resource ought to use one of the enclosed URIs. Clients with link-editing capabilities ought to automatically re-link references to the effective request URI to one or more of the new references sent by the server, where possible.

The server SHOULD generate a Location header field in the response containing a preferred URI reference for the new permanent URI. The user agent MAY use the Location field value for automatic redirection. The server's response payload usually contains a short hypertext note with a hyperlink to the new URI(s).

Note: For historical reasons, a user agent MAY change the request method from POST to GET for the subsequent request. If this behavior is undesired, the 307 (Temporary Redirect) status code can be used instead.

A 301 Moved Permanently response is cacheable by default; i.e., unless otherwise indicated by the method definition or explicit cache controls (see Section 4.2.2 of [RFC7234]).

Source / Quote by: The 301 Moved Permanently HTTP Status Code is specified by section 6.4.2 of RFC7231.

How to throw a 301 statuscode with PHP?

To throw the HTTP status code 301 on a web page, the PHP function http_response_code can be used. The syntax is as follows: http_response_code(301) (PHP 5 >= 5.4.0, PHP 7, PHP 8)

Test the 301 HTTP status code

In order to be able to display the HTTP status code (in this case 301 Moved Permanently) and other information on the client side, the development console must be opened with F12. Afterwards you have to navigate to the tab "Network". Now you can open the page, in the network tab you should see the web page (example index.php). This must be selected and then the Herder section must be selected. Here the user will see the following result:

Status code 301 Moved Permanently
Overview
URL: https://http-statuscode.com/errorCodeExample.php?code=301
Status: 301 Moved Permanently
Those: Network
IP address: XX.XX.XX.XX
Status code 301 Moved Permanently

Browser compatibility of the 301 status code

Chrome Yes
Edge Yes
Firefox Yes
Opera Yes
Safari Yes
Chrome Android Yes
Firefox for Android Yes
Opera Android Yes
Safari on iOS Yes
Internet Yes
WebView Android Yes

Constants in programming languages

HttpStatusCode.MovedPermanently
http.StatusMovedPermanently
Response::HTTP_MOVED_PERMANENTLY
httplib.MOVED_PERMANENTLY
http.client.MOVED_PERMANENTLY
http.HTTPStatus.MOVED_PERMANENTLY
:moved_permanently
Author: Tony Brüser
Author: Tony Brüser

Tony Brüser is an enthusiastic web developer with a penchant for HTTP status codes.

LinkedInGitHub