I have added 301 redirect on my website by mistake (because I was doing maintenance). Now lots of people can't get back to my website, because they are still redirected to other page - eventhough I removed redirection (even deleted htaccess). As much as I searched around it's because htaccess (or 301 redirect) is cached in users browser and I wasn't able to find any solution for this. Is there any way to fix this, I can't just loose hundreds of visitors because of something like this?
-
Have you tried turning it off and on again? – hjpotter92 Aug 02 '14 at 13:22
-
Can you restart your website server ? – d.danailov Aug 02 '14 at 13:25
-
I haven't tried restarting server and yes, I can restart it - I use VPS and DA panel. Should I restart just Apache or also anything else? – Martha Smithers Aug 02 '14 at 13:27
-
I have restarted the whole server and it's the same, redirect is still happening. – Martha Smithers Aug 02 '14 at 13:43
1 Answers
This page explains what is going on in good detail:
Basically, modern browsers cache the redirect response for 301 for some indeterminate amount of time and will not make an updated request to your old web page to refresh it. Users can manually clear the cache and, because it is a cache, data can be purged if the browser needs more space for other data (like other redirects).
This SuperUser question resolves the caching issue from the client's end:
One interesting answer is:
In this answer, the user points out that the browser treats http://example.com/
and http://example.com/?
as two different URLs. You could go to the "new" site and setup an HTTP 302 redirect pointing back to the original page with a ?
on the end and it should load. If they original page already had a query as part of the URL, you can simple add an &
to the end to achieve the same result.
It's not perfect -- it is a different URL after all -- but at least they'll be able to view your old site.
Note that your web application may try to redirect empty queries or invalid queries back to a "clean" page, which you may have to disable to get the intended result.
UPDATE
One other option is to put a redirect from the new site back to the old site (make this a 302 or 307 redirect to avoid the 301 problem you're currently having). From my testing, Chrome will remove the old redirect when it does this. It may throw a "redirect loop" error, but only once. I was unable to reproduce the cached redirect problem at all with the latest version of Firefox. Other browsers' behavior is probably going to be inconsistent.

- 3,857
- 25
- 23
-
I can't use different URL, to many things is connected to that URL. Is there any other way? How long does it take for that cache to clear by itself? – Martha Smithers Aug 02 '14 at 14:04
-
I added another possible solution. The browsers will hold on to the cached entry for as long as they can (typically, limited by space). There is no set time for the cache to clear by itself, and browser behavior isn't consistent in this regard. – hrunting Aug 02 '14 at 16:47
-
I can't try the second possible solution in my case, because I made redirection to google, which I don't own and can't made redirections there. :) But I tried just for a test and this solution does work, but you had to made redirection to your own website (which you don't use - if you use it, again users from that page will be redirected to second page because of that redirect). Is there maybe any way to check in htaccess if user came from 1. redirected page (or had cached redirect) then he is redirected, but if he didn't he is not? – Martha Smithers Aug 03 '14 at 12:17
-
If people are actually requesting the page via your old, unredirected URL, then you don't need to conditionally redirect them at all. The cache has been cleared at that point. If you don't have access to both ends of the redirect, there is nothing you can do as the server operator to clear the cache other than to ask your users to clear their cache manually. – hrunting Aug 03 '14 at 12:57
-
Well the problem is that I can't ask people to clear cache, because they can't see my page anymore. So basically if you don't have access to second page (where users ware redirected) there's nothing you can do? But if you have access to that page, then you can make redirect back - but what code should we use to check if visited URL is the one which has cache problem or normal one and then redirect back only is user came from redirected URL? – Martha Smithers Aug 03 '14 at 13:55
-
Yes, if you've redirected people to a server that you don't control, you don't have any options other than to wait or tell people via some other method (email, some other page on the site, etc.). If someone visits the URL on your site with "cache problem", then they don't have a problem at all because they're not using the result of a cached redirect. – hrunting Aug 03 '14 at 14:08