Post/Redirect/Get

Jump to: navigation, search
Diagram of a double POST problem encountered in user agents.
Diagram of the double POST problem above being solved by PRG.

Post/Redirect/Get (PRG) is a web development design pattern that prevents some duplicate form submissions, creating a more intuitive interface for user agents (users). PRG supports bookmarks and the refresh button in a predictable way that does not create duplicate form submissions.

When a web form is submitted to a server through an HTTP POST request, a web user that attempts to refresh the server response in certain user agents can cause the contents of the original POST request to be resubmitted, possibly causing undesired results, such as a duplicate web purchase.[1]

To avoid this problem, many web developers use the PRG pattern[2]—instead of returning a web page directly, the POST operation returns a redirection command. The HTTP 1.1 specification introduced the HTTP 303 ("See other") response code to ensure that in this situation, the web user's browser can safely refresh the server response without causing the initial POST request to be resubmitted. However most common commercial applications in use today (new and old alike) still continue to issue HTTP 302 ("Found") responses in these situations.

The PRG pattern cannot address every scenario of duplicate form submission. Some known duplicate form submissions that PRG cannot solve are:

  • If a web user refreshes before the initial submission has completed because of server lag, resulting in a duplicate POST request in certain user agents.

PRG is also used in search engine optimization (SEO), especially for filter navigation in online stores [3].

Usage in Search Engine Optimization

Filter navigation in online stores (often referred to as layered or faceted navigation) allows the user to filter product collections by product features such as color, size, material and so on. However, from a search engine optimization point of view, this function is problematic because (Near-) Duplicate Content and an almost infinite number of additional URLs are created, which in turn leads to a waste of crawling budget [4].

The PRG pattern is an approach to avoid these SEO problems related to filter navigation [4] and delivers better results compared to other SEO solutions that address the mentioned issues only inadequately [5]. However, the PRG pattern is usually not supported by Content Management Systems (CMS) and Online Shop Systems by default and has to be implemented individually (example implementation for Magento online stores [6]).

Bookmarks

User agents (such as browsers) store only the URI of an HTTP request as a bookmark. Because of this, an HTTP POST request that results in a response based on the body of the HTTP POST request cannot be bookmarked. By using the PRG pattern, the URI of the request can safely be bookmarked by a web user.

Proxy servers

Since redirects are using absolute URIs, one has to take care about proxy servers (HTTP→HTTPS) and reverse proxy servers. If your application is such that a user uses an SSL tunnel to reach your site, this can cause problems also. (You may be able to use the Referer header to discover the domain and port the user is actually entering.)

References

  1. ^ Grinberg, Miguel (2014). Flask Web Development. O'Reilly. pp. 44–46. ISBN 978-1-449-37262-0. 
  2. ^ p36, "Universal Design for Web Applications", by Wendy Chisholm and Matt May, O'Reilly Media, Inc., 2008
  3. ^ "Post-Redirect-Get". Ryte.com. Retrieved 2018-05-19. 
  4. ^ a b "Large Site SEO Basics: Faceted Navigation". Moz. Retrieved 2018-05-19. 
  5. ^ "l▷ SEO Optimization for Layered Navigations with PRG Pattern ✔ | JaJuMa-Blog". JaJuMa. Retrieved 2018-05-19. 
  6. ^ "l▷ PRG Pattern Extension for Magento 2 ✔ | JaJuMa-Develop". JaJuMa. Retrieved 2018-05-19. 

External links