How to redirect an html page only once?

I want to redirect an html page on my website (lets say, 1st page) to another html page on a different website (lets say, 2nd page) and then again from this 2nd page back to the 1st page on my website. i.e.
Redirect this page:

mysite.com/page1.html

to:

othersite.com/somepage.html

(referred to as 2nd page from here on)

and finally back to:

mysite.com/page1.html

(referred to as 1st page from here on)

I want no more redirects from this point onwards…

I am currently using this code on the 1st page (my website):

<meta http-equiv="REFRESH" content="5;url=http://www.othersite.com/somepage.html">

As you can see that this code redirects the visitors to the 2nd page which will then redirect them again back to the 1st page.

But the problem with it is that, when the visitors return back to the 1st page, they are again redirected back to the page they came from (2nd page). Thus, the users end up in an endless loop.

What I would like done is that, when the first time a user gets redirected to the 2nd page (from the 1st page) and then again back to the 1st page (from the 2nd page) s/he should not be redirected back again to the 2nd page and stay on the same 1st page. i.e. the 1st page’s code redirects the visitors only once when they visit it for the first time to the 2nd page, the 2nd page then redirects them back to the 1st page but here the 1st pages’ code doesn’t redirect them again to the 2nd page and so the visitors end up on the 1st page.
How can I modify the code above so that it does what I want it to do?

Hi lucastprice. Welcome to the forums. :slight_smile:

Out of interest, what is the point of this?

You can use a server side session. Set a session variable in page 1 when it is first called. At the top of page 1, check if the session variable exists. If it does, then don’t redirect to page 2. If it doesn’t exist, then set it and redirect to page 2.

If using PHP you can redirect with header().

Thanks for the reply … but I am completely new to web designing and only know a little HTML … I would really appreciate if you or anyone else here can really take out some time whenever feasible to show step by step what exactly should I do, what code do I need to place in my webpage and where exactly should I put the code…

Off Topic:

I’ve moved this to the programming section, where you will get more help with server side issues.

Or using JavaScript?

window.location = ‘page.html’

The problem with that is, that it won’t work in devices and/or browsers that do not have javascript available. If you use sever side code to redirect, then it will work 100% of the time.

If something can be done both server and client side then it’s always better to do it server side if you need it to work 100% of the time :slight_smile:

Does anyone know what is the exact code I need for doing this … sorry but i don’t know any php…