EN
HTTP - 301 vs 302 redirection - when to use which one?
5
points
In this short article we want to explain when to use 301
or 302
location redirection status with HTTP requests.
Location redirection with 301 status
It should be used when we want to replace permanentally some URL and we want to tell to search engines that URL is depricated and was replaced by new one.
Note:Â many browsers cache responces withÂ
301
 status, that causes the web browser doesn't request server again opening directly new one link - it can lead to reopen URL from previous request.
Browser request example:
GET /path-to-old-file-name.html HTTP/1.1
Host: www.example.org
Server response example:
HTTP/1.1 301 Moved Permanently
Location: https://www.example.org/path-to-new-file-name.html
Location redirection with 302Â status
It should be used when we want to:
- have many links to same resource and all of them are important too (it is like shortcut of some link that)
- be sure that web browser requests server always before redirection occures to get most current redirection URL becouse it can be changed by server in anytime.
Browser request example:
GET /index.php HTTP/1.1
Host: fb.com
Server response example:Â
HTTP/1.1 302 Found
Location: https://facebook.com/index.php
Advices (Browser Caching of 301 Redirects)
- Clear your browser cache each and every time you make a change to a 301 redirect,
- Never put a 301 (permanent) redirect in place unless it is truly permanent!
- Always implement 302 (temporary) redirects first, then change them to 301 (permanent) redirects once you’ve tested them!