[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

browser redirect cache

Posted on 2006-05-31
24
Medium Priority
?
1,615 Views
Last Modified: 2013-11-19
I have a page www.test.com/test/index.html
the index.html redirect to an old page.
I've changed the index.html to redirect to the new page.
but while type in www.test.com/test, it still go to the old page.
If I open up another browser which I never typed in www.test.com/test before, then it will go to the new page, but how can I force the browser (IE or FireFox) to redirect my page to the new page instead of the old one?

Thanks.
0
Comment
Question by:xiaoyunwu
  • 11
  • 11
  • 2
24 Comments
 
LVL 5

Expert Comment

by:Joe Jenkins
ID: 16800074
Depending on your operating environment and web server info you can do it two ways.

Apache or non-Windows that can make use of an .htaccess file:

redirect 301 /somedirectory/filename.ext http://www.yourdomain.net/somedirectory/newfile.ext

You can also modify the httpd.conf file to handle redirects.

On Windows IIS:

With Microsoft IIS, you can easily redirect one root  to another root , but it is not so easy to redirect specific files. To do that, you need some code I'll include below.   However, if you keep your file structure intact as you change urls (i.e., the same url works for http://www.olddomain.com/filename.html and http://www.newdomain.com/filename.html), then the task is pretty easy.  Just open the IIS control panel, right click on the website and select "Properties", then select the "Home Directory" tab, and click on "a redirection to a url." Redirecting the root URL will automatically redirect all the files in the old URL to their corresponding file locations on the new URL. This will work well if you need to move an entire site or virtual directory.

You can also do it with VBScript:
<%@ Language=VBScript %>
<%
   Response.Status="301 moved permanently"
   Response.AddHeader "Location", "http://www.yourdomain.net/somedirectory/somenewfile.html
%>

That will accomplish what you're looking for.

Joe Jenkins
0
 

Author Comment

by:xiaoyunwu
ID: 16800472
my index.html is written to redirect from the old page to a new page, and I know how to do it.

here is the index.html
<html>
<script>
function redirect()
{
document.location.replace("http://www.test.com/newpage.html");
}
</script>
<body onload=redirect()>
</html>

My problem is: the browser somehow cache the redirection, so it's still redirect to the old page, instead of new one even though I've changed index.html.

I've cleared all the cache, but still go to the old page.
0
 
LVL 5

Expert Comment

by:Joe Jenkins
ID: 16801779
Hmm.  Check Tools -> Internet Options and then click "Settings"  under temp Internet files on the General Tab.  Change it to "Every Visit to the Page" and delete all offline content to see if that remedies the problem.

Joe Jenkins
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:xiaoyunwu
ID: 16802093
No, it does not work, if I change the content of old page, it will show up the change, so it clears the cache of the page, but it's holding the redirect information somewhere. and "Shift + refresh" only refresh the old page, since it's a redirect, I can't seem to get rid of the redirect information in browser.
0
 
LVL 6

Expert Comment

by:shambhusingh2004
ID: 16802685
Create a test.asp page and place following code

<%
Response.Buffer = True
%>
<HTML>
<BODY>
<%
If 1 = 1 Then
   Response.Clear
   Response.Redirect "http://www.test.com/newpage.html"
End If
%>
<%
Response.End
%>
</BODY>
</HTML>

Can you please check and let me know is it helpful for you.

Regards

Sanjeev
0
 

Author Comment

by:xiaoyunwu
ID: 16806736
I can't put a test.jsp, it got to be index.html, since I will just let customer come to the directory:
www.test.com/test, so in the index.html which in put under the test directory have to do the redirect.
0
 
LVL 6

Expert Comment

by:shambhusingh2004
ID: 16810360
Sorry, Create a <b>index.asp</b> page and place following code it will work like index page and redirect your domain users to your newpage.html

<%
Response.Buffer = True
%>
<HTML>
<BODY>
<%
If 1 = 1 Then
   Response.Clear
   Response.Redirect "http://www.test.com/newpage.html"
End If
%>
<%
Response.End
%>
</BODY>
</HTML>

Can you please check and let me know is it helpful for you.

Regards

Sanjeev
0
 

Author Comment

by:xiaoyunwu
ID: 16810433
I'm not using ASP, I'm using broadvision, and only use javascript. Sorry!
0
 

Author Comment

by:xiaoyunwu
ID: 16810447
By the way, what if someone only have the ability to use basic html, javascript. No server side processing?
0
 
LVL 5

Expert Comment

by:Joe Jenkins
ID: 16817743
Well, in that case, you'll want to use a server redirect method that I mentioned above.  That way there is no question of *IF* it will redirect because the server will process the redirection before the user ever sees anything.  So the .htaccess method or the IIS method of rerouting the whole directory would be the optimal approach for your situation.  You can also change the 404 error message page to include, "The page you are looking for is no longer available or has MOVED.  Click here for the home page or site map."  Your wording will vary but you get the point.  That way when they go to the page that doesn't exist anymore, you can refocus them back to the main page of the site.  This is especially useful when lauching a new site and not having the capability of changing the server level parameters to accomplish this task.

Joe Jenkins
0
 

Author Comment

by:xiaoyunwu
ID: 16818412
that's too complicated, and I am not allowed to make those changes.

I can control the code I put into index.html and my browser, that's all.
0
 
LVL 5

Expert Comment

by:Joe Jenkins
ID: 16823977
If you can't make the other changes that I recommended and you're limited to just using HTML, you'll have to use a META tag redirect or a javascript redirect.  The META redirect will be your most inclusive method of redirect.  You can do it like this:
<html>

<head>
<title>Old Page -> Redirect to New Page</title>
<meta http-equiv="refresh" content="3; url=http://www.newlocation.com/newdirectory/another/nameofnewpage.html">
</head>
<body>
-- insert some code here that fits your website letting the user know the new address and to update their bookmarks, etc.  
</body>
<html>

---
The "content="3" portion is the number of seconds to wait before redirect.  the url is the new site.  

The javascript method:

<script type="text/javascript">
<!--
window.location = "http://www.newlocation.com/newdirectory/newfile.html"
//-->
</script>

You can also write a function that will delay, if necessary I will outline that as well.

I hope this helps you.  Your options become quite limited without server access or advanced languages.  :)

Joe Jenkins
0
 
LVL 5

Expert Comment

by:Joe Jenkins
ID: 16823991
I have a few extra minutes so here is the time delay code here using the same code above I used in the meta redirect:

<head>
<title>Old Page -> Redirect to New Page</title>
<meta http-equiv="refresh" content="3; url=http://www.newlocation.com/newdirectory/another/nameofnewpage.html">
<script type="text/javascript">
<!--
function redirect_with_delay(){
window.location = "http://www.newlocation.com/newdirectory/another/nameofnewpage.html"
}
//-->
</script>
</head>
<body onLoad="setTimeout('redirect_with_delay()', 3000)">
-- insert some code here that fits your website letting the user know the new address and to update their bookmarks, etc.  
</body>
<html>

The timeout is x 1000.  3 seconds equals 3000, 5 seconds equals 5000, etc.  

:)

Good luck,
Joe Jenkins
0
 

Author Comment

by:xiaoyunwu
ID: 16835139
That's not my question.

Look at my comment above, I copied here.

here is the index.html
<html>
<script>
function redirect()
{
document.location.replace("http://www.test.com/newpage.html");
}
</script>
<body onload=redirect()>
</html>

My problem is: the browser somehow cache the redirection, so it's still redirect to the old page, instead of new one even though I've changed index.html.
0
 
LVL 5

Expert Comment

by:Joe Jenkins
ID: 16835268
Right, and it will continue doing so.  

It's probably not caching the page, per se. If you continue to put in the same old address, it's going to have to redirect the page again until you employ a server level redirect as mentioned above in one of my first responses.   This is because the browser doesn't understand that you moved your page, and doesn't care.  It just does what it's told.  Does the redirect work when you type in the old address?  If the answer is a resounding "Yes", then that is the most you will be able to do at a client level.  The only further step would be at the server level.  Submit a support ticket to the hosting company to update the pointer to force a 301 redirect for you.

Joe Jenkins
0
 

Author Comment

by:xiaoyunwu
ID: 16845514
Sorry, please help me here.

Here is how I think the browser works:
when I first type in
http://www.test.com/test
the browser go to look for index.html
and the index.html will redirect to old page.

Then, I change my index.html to redirect to new page instead.
After that, I type in http://www.test.com/test again in the browser,
and the index.html will be read by browser, and the index.html is pointing to new page now. But the browser instead just still redirect to old page.

so there's no way for me on the client browser side or in the index.html to prevent this?
0
 
LVL 5

Expert Comment

by:Joe Jenkins
ID: 16845589
Can you post the code from the index.html page so I can see it?  It sounds like something may be off somewhere.  So index.html used to route to PAGE-A.html and you changed it to route to PAGE-B.html and it's still, for some reason, routing to PAGE-A.html, correct?  If I can see the code I'm sure I can be of more help.

:)

Joe Jenkins
0
 

Author Comment

by:xiaoyunwu
ID: 16897413
Yes, you're right.

Here is the code for index.html:

<html>
<script>
function redirect()
{
document.location.replace("http://www.test.com/newpage.html");
}
</script>
<body onload=redirect()>
</html>
0
 

Author Comment

by:xiaoyunwu
ID: 16983374
Can someone help, please? thanks.
0
 
LVL 5

Expert Comment

by:Joe Jenkins
ID: 16986203
Let's play with cache-control a little bit.  Replace your test code with this:

<html>
<head>
<title>Old Page -> Redirect to New Page</title>
<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">
<meta http-equiv="refresh" content="0; url=http://www.google.com">
<script>
function redirect()
{
document.location.replace("http://www.test.com/newpage.html");
}
</script>
</head>
<body onload=redirect()>
</body>
</html>


You had some syntax errors in your code above.  Try this and tell me how it does for you.  What this code does is tell the browser to NOT cache the page.  

Joe
0
 
LVL 5

Accepted Solution

by:
Joe Jenkins earned 2000 total points
ID: 16986290
I have tested this solution in Firefox and Internet Explorer 6 and it works by design.

<html>
<head>
<title>Old Page -> Redirect to New Page</title>
<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">
<META HTTP-EQUIV="Expires" CONTENT="0">
<meta http-equiv="refresh" content="0; url=http://www.google.com">
<script>
function redirect()
{
document.location.replace("http://www.test.com/newpage.html");
}
</script>
</head>
<body onload=redirect()>
</body>
</html>

I put the meta http-equiv refresh command in there merely as a reference in case you want to try that one INSTEAD of the javascript solution.  You can also immediately expire the page by adding <META HTTP-EQUIV="Expires" CONTENT="0"> to the header that I pasted in above.  

This would be my choice.  It worked in all cases.

Joe
0
 
LVL 5

Expert Comment

by:Joe Jenkins
ID: 16994647
I'm revisiting this one today to follow-up with you.  I'd love for you to be able to close this question with success.  Please note that in my above examples that I included both a meta refresh and a javascript solution.  You are more than welcome to use both, just make sure the addresses are the same for the redirect addresses.  Personally, I would add both to my site as some users (especially server operating systems) disable or don't support javascript by default.  This way, they'll still be able to get to your page if it's disabled.  

If you want to take it a step further, and use good practice, make sure between your body tags you give them yet another way to get to the new page:

<body>
<p>The page you have requested has been permanently moved.  Please update your bookmarks to the new location. <br><br>Your browser will redirect you automatically, but if it does not you can <a href="newpage.html" target="_self">click here</a> to go to the new page.<br><br>Thank you,<br>Webmaster<br><br> For additional reference, the new page location is located at: http://www.thenewdomain.com/somedir/newpage.html
</body>

Joe Jenkins
0
 

Author Comment

by:xiaoyunwu
ID: 17000925
Thank you so much Joe, it worked. :)
0
 
LVL 5

Expert Comment

by:Joe Jenkins
ID: 17001004
Fantastic!  I'm glad I could help!

Joe Jenkins
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

FAQ pages provide a simple way for you to supply and for customers to find answers to the most common questions about your company. Here are six reasons why your company website should have a FAQ page
There’s a good reason for why it’s called a homepage – it closely resembles that of a physical house and the only real difference is that it’s online. Your website’s homepage is where people come to visit you. It’s the family room of your website wh…
This video teaches users how to migrate an existing Wordpress website to a new domain.
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.
Suggested Courses

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question