The HTTP response status code 301 Moved Permanently is used for permanent URL redirects, which means the current link or record uses URLs whose responses are accepted to be updated. New URLs should be provided in the Location field that is included with the response. 301 redirects are considered best practices for increasing users from HTTP to HTTPS.
RFC 2616 states that:
- If the client has the ability to edit links, it must update all references to the Request URL.
- The response can be cached unless otherwise indicated.
- Unless the request method is HEAD, entities must contain hypertext notes with hyperlinks to new URLs.
- If the 301 status code is accepted in response to a request of any type other than GET or HEAD, the client must ask the user before diverting.
Video HTTP 301
Contoh
Client Request:
GET/index.php HTTP/1.1 Host: www.example.org
Server response:
HTTP/1.1 301 Moved Permanently Locations: http://www.example.org/index.asp
Here's an example using an.htaccess file to redirect an unsafe URL to a secure address without the "www" prefix:
RewriteEngine On RewriteCond% {HTTPS} is off RewriteCond% {HTTP_HOST} ^ www \. (. *) $ [NC] RewriteRule ^ (. *) $ Http://% 1/$ 1 [R = 301, L] RewriteCond% {HTTPS} is active RewriteCond% {HTTP_HOST} ^ www \. (. *) $ [NC] RewriteRule ^ (. *) $ Https://% 1/$ 1 [R = 301, L] RewriteEngine On RewriteCond% {SERVER_PORT} 80 RewriteRule ^ (. *) $ Https://example.com/$1 [R, L]
Here's an example of using a PHP redirect:
Simple equivalent for nginx configuration:
location/old/url/{ Ã Ã Ã Ã return 301/new/url/; }
Here's one way to redirect using Express.js:
app.all ("/old/url", (req, res) = & gt; { Ã Ã Ã Ã res.redirect (301, "/new/url"); });
Search engine
Both Bing and Google recommend using 301 redirects to change the page URL as shown in search engine results.
Maps HTTP 301
See also
- Hypertext Transfer Protocol
- List of HTTP status codes
- URL redirects
References
Bibliography
External links
Source of the article : Wikipedia