Douglas Gaskell
Douglas Gaskell

Reputation: 10030

HTML, JS, or php redirect just appends the destination to the current path

I'm trying to redirect a user from a link to another domain.

ie: mysite.com/xyz sends the users to www.google.com. I am including a google analytics script, then trying to redirect, however all that is happening is the destination is appended to the current path and the page reloads. So I end up with: mysite.com/www.google.com

Code (Tried all three):

JS:

window.location = "www.google.com";

PHP:

header("Location: ".$link[0]['destination']);

HTML:

<meta http-equiv="refresh" content="0;www.google.com">

All the the above just append www.google.co to the url. How can I redirect the page on load?

Upvotes: 0

Views: 73

Answers (1)

Aloso
Aloso

Reputation: 5397

Don't forget http:// or https://. Otherwise the browser or php engine think that you want to redirect to a specific file in the same server directory.

I advise you not to use javascript: it might be disabled in the client's browser.

You forgot a fourth way:

header('refresh: 3; url=http://www.google.com');

This redirects to Google after 3 seconds. I think it's more straightforward than a meta tag.

Upvotes: 2

Related Questions