skip to Main Content

I need to show my users a slightly different version of the front-page before opening date. The idea was to redirect them to home.html in the index.php (the main-site) by using header("location:home.html"), and after the opening, remove that redirect so they load the real index.php.

The problem is, if I do that, will the browser cache the redirect and take them to cached version of home.html even after I have removed the redirect from the index.php? If so, how do I prevent that?

The end goal is, show the user uncached brand new version of the site after opening date.

2

Answers


  1. There are multiple kinds of redirections. You want a temporary.

    header("HTTP/1.1 307 Temporary Redirect");
    header("Location: https://example.com/home.php");
    

    PHP is not caching redirects, but the browser may. So when used temporary it won’t.

    Login or Signup to reply.
  2. When you call

    header("location:home.html")
    

    basically, there will be a redirect to the home.html page. header itself does not cache anything, it’s just a function.

    Your browser may cache CSS and JS files, but it will never cache home.html itself. home.html is being sent from your server to the browser as it is. Yet, of course, you may have server-side caching in your equation, that is, it’s possible that even though you have changed home.html, it may have been changed in dev mode, whereas, an older home.html may be in use on your server, in which case the cache could be emptied, or somehow, depending on your server-cache brand you may force-load home.html.

    All in all, you should not be worried about caches being used by header(), if you have a caching problem on your server-side, empty the cache, or force-load the page. If you are afraid of caching problems in your browser, then you can add some parameter to the URL, like:

    https://your/path/to/this/file.css?version=3

    and always change this version whenever you have a new release to force browsers to load the new file rather than reuse its older version.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search