Jump to content

How to redirect users properly?


Wuhtzu

Recommended Posts

Hey

 

I have two domains:

 

www.domain1.com

www.domain2.com

 

When a visitor enters www.domain1.com I want him/her to see: "The website has moved. Redirecting to www.domain2.com" and then of course be redirected. But how do I do this properly? Here I especially think of doing it right according to W3.org: http://www.w3.org/QA/Tips/reback

 

I should avoid using <META HTTP-EQUIV=REFRESH CONTENT="1; URL=www.domain2.com"> but if I can't use that, how shall I get a textmessage displayed for, say, 3sec and then redirect using for example header("Location: www.domain2.com"); ?

 

Hopefully you understand my problem and have a suggestion on how to do it :)

 

 

Best regards

Wuhztu

Link to comment
https://forums.phpfreaks.com/topic/40500-how-to-redirect-users-properly/
Share on other sites

It's perfectly fine to carry on using that method but there are other ways.

 

You can set up a redirect by logging into the control panel of the domain name as there should be an option there for it but it'll be transparent - that is, the user won't know they've been relocated unless they look at the URL.

 

Using the method you're using now will allow users to see the domain has changed and update their bookmarks accordingly.

 

Another method is using a ".htaccess" file on the server to redirect but again, this is transparent.

The above example are the way to do it..

 

If you use your way make a plain HTML file with the content that reads something like this:

 

"

We Have Moved. You Will Be Directed To The New Site In 10 Seconds.

 

http://www.locationsofnewsite.com

 

If you are not forwarded to the new site or don't wish to wait click the above link.

"

 

Change your meta from 1 to 10 or whatever given number.  This will alow your users to take note of what is going on.

<html>
<head>
  <title>domain1</title>
  <meta http-uquiv="refresh" content="10; URL=www.domain2.com">
</head>
<body>
  <div align="center">
  We have moved, please update your bookmarks to:<br /><br />
  <a href="http://www.domain2.com">http://www.domain2.com</a><br /><br />
  If you are not redirected or don't want to wait click the above link.
  </div>
</body>
</html>

Thanks for your input..

 

I know the <meta http-uquiv="refresh" content="10; URL=www.domain2.com"> will work and it does what I want to do, which is to let the visitor see message saying the site has moved and then redirect the visitor to the new url.

 

But W3C (w3.org) recommends that the "redirecting by refreshing"-method is not used, because it breaks the users Back-button and that's why I was looking for another method. But on the other hand the user has nothing to go back to - or does he ?

 

Take the following scenario:

 

#1: The user is currently viewing www.google.com

#2: He decides to go to www.domain1.com

#3: On www.domain1.com i redirect him using <meta http-uquiv="refresh...> to www.domain2.com

#4: He is now viewing www.domain2.com

#5: He decides to go _back_ to www.google.com (which he should be able to do with 2 clicks on the back button)

#6: He hits _back_ and gets back to www.domain1.com

#7: He is redirected back to www.domain2.com again (if he does not hit the back button in 10sec, say we said content="10..")

 

 

So the only thing saving me from breaking the users back-button is my redirect waits 10sec and he should be able to hit the button again within 10sec..

 

But I would like to skip this whole problem by using some other method, as w3.org recommends - any suggestions?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.