Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8459073
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T13:14:53+00:00 2026-06-10T13:14:53+00:00

A while ago all browsers changed their behaviour and started caching 301 redirects, I

  • 0

A while ago all browsers changed their behaviour and started caching 301 redirects, I would like to know how to do a 301 redirect that is not cached in php?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T13:14:54+00:00Added an answer on June 10, 2026 at 1:14 pm

    301 is a permanent redirect, so caching makes sense. If your redirect isn’t permanent, use 307 (temporary redirect), 302 (found) or 303 (see other).

    See here for the appropriate use cases.

    To elaborate on the differences between these three:

    • 307 is the generic, temporary redirect for when a resource is moved. For example, a URL like domain.com/news/latest might do a 307 redirect to the latest news article, domain.com/news/article-594873. Since this temporary redirection may persist for a while (that particular article may be the latest for several hours), browsers might cache the redirect. To control the degree to which they do, use cache control headers.
    • 303 is the redirect that must not be cached, ever. For example, POSTing a new article to domain.com/news might create a new news article, and a 303 redirect to it is provided to domain.com/news/article-978523. Since another POST request results in a completely different, new article being created, it cannot be cached.
    • 302 is a bit stranger, I’ve never used it myself. Apparently it’s more of a legacy substitute for the 303, for earlier HTTP 1.0 version clients who do not understand the 303.

    Since you asked specifically about PHP:

    <?php
    function header_redirect_permanent($url)
        {
        header($_SERVER['SERVER_PROTOCOL'] . ' 301 Moved Permanently', true, 301);
        header('Location: ' . $url);
        }
    
    function header_no_cache()
        {
        header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
        header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // past date to encourage expiring immediately
        }
    

    You can stop agents from caching a 301 as well, if you must, using the above cache control headers like this:

    header_no_cache();
    header_redirect_permanent($url);
    

    or simply add

    header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
    header('Expires: Sat, 26 Jul 1997 05:00:00 GMT');
    header('Location:'.$url, true, 301);
    exit;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I started C# a while ago and really like it. I work with VS
I deleted all my .xib files a while ago, and recently changed my identifier.
A while ago, I came to the realization that a way I would like
I have a website that I built a while ago. All of sudden, without
A while ago I asked myself, when I write something like this: char* first(int
a while ago i could comment any code in php with netbeans like this:
Authenticating to our Ubuntu EC2 instance worked fine until a little while ago. All
i've started unit testing a while ago and as turned out i did more
I have a domain, call it mydom.com. A while ago I started using Google
Quite a while ago, I heard about Object databases. Cool concept and all. Now,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.