Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do browsers cache 301 redirects with query strings

I'm looking to put in a 301 redirect to an application for specific values of a query string parameter.

For Example:

  • http://www.example.com/page?id=1 → redirect to a new page
  • http://www.example.com/page?id=2 → render normal response

How do browsers cache the redirect?

Specifically, after visiting the first URL, will some browsers start performing a 301 redirect for the id=2, or are redirects based on the full URL?

like image 578
jkelley Avatar asked Mar 12 '13 19:03

jkelley


People also ask

Do browsers cache 301 redirects?

In the absense of cache control directives that specify otherwise, a 301 redirect defaults to being cached without any expiry date. That is, it will remain cached for as long as the browser's cache can accommodate it.

Does Chrome cache 301 redirects?

Google Chrome will cache your 301 redirects. To get around this, and to keep the tabs open, you'll just need to clear your browser cache.

How does browser handle 301?

The HyperText Transfer Protocol (HTTP) 301 Moved Permanently redirect status response code indicates that the requested resource has been definitively moved to the URL given by the Location headers. A browser redirects to the new URL and search engines update their links to the resource.


1 Answers

Browser will definitely cache the 301 redirect because it's a permanent redirect. Basically you're telling the browser never to look at the original URL and to automatically go to the second URL. Same thing happens for any search engines. If you ever plan to use that original URL again, make sure you use a temporary redirect.

Specifically, after visiting the first URL, will some browsers start performing a 301 redirect for the id=2, or are redirects based on the full URL?

No, the browser should see each URI in it's entirety, so page?id=1 is a different URL than Page1?Id=2 and the 301 redirect would only apply to the first url.

Keep in mind that the browser is doing the redirect and implementing its own rules based on its interpretation of the HTTP spec. If there are any bugs in the browser you could get unpredictable results, but the short answer is that they're different requests to different urls and each get their own HTTP status code therefore they can be treated as separate pages.

like image 104
Dave Mroz Avatar answered Dec 28 '22 07:12

Dave Mroz