Redirecting External Links

Joined
Jul 21, 2010
Messages
40
Reaction score
4
Hi everyone. I've been trying to figure out how to redirect external links sort of like the way BHW does it but have come up with no success. Is there a way to:

1) Send all external links to an internal php page
2) Notify where the user is going
3) Send them off.

Thanks!
 
Hi everyone. I've been trying to figure out how to redirect external links sort of like the way BHW does it but have come up with no success. Is there a way to:

1) Send all external links to an internal php page
2) Notify where the user is going
3) Send them off.

Thanks!
Can you explain a bit more what you mean? Seems relatively easy but I don't want to explain something if I'm not on the same page as you.
 
What you're looking for is probably this:

Code:
header( 'Location: http://www.new.com/new_page.html' );
Of course you can use a GET query string parameter if you want to redirect to a new location passed via the URL...

Code:
http://www.w3schools.com/PHP/php_get.asp
Also, if the redirection is not a static, hard-coded URL you might want to implement a few security checks.

P.S. Almsost forgot... You might want to add some javascript to do the tracking you were mentioning in your OP.
 
Hi

I am intersting also if is there any products to add it to fourm to do that , and to hide my site from the site user will visit .

Thankx
 
Good input so far guys.

So a typical scenario I'm thinking of is a user is on my website (specifically a wiki) and clicks on an external link. I want to send them to a page on my website that displays the url address that they are going to briefly before sending them off to the external website. However, before the URL is displayed I want to be able to check the link for security purposes and modify it if necessary. If possible, I want to be able to keep the original page as the referrer to the new website.
 
On the PHP side of things, you'd be looking to do something like this.

Create a file, out.php

Within out.php, you'd do something like this

Code:
<?php
  if(isset($_GET['s']) && $_GET['s'] != '') {
    $target_url = $_GET['s'];
    // do whatever you desire w/ $target_url such as cleaning it
    // storing it in a DB, etc (if you store it, sanitize it first)
    // also if magicquotes is enabled you'll need to strip slashes
    // before referencing it below
  } else {
    // error handling, such as returning to previous URL
  }
?>
<html>
   <head>
 [FONT=monospace]   <script type="text/javascript">
     <!--
     function redirect() {
       window.location = "<?= $target_url ?>";
     }
     //-->
   </script>
[/FONT]  </head>
   <body onload="setTimeout('redirect()', 5000)"> <!-- 5 second delay -->
     You're about to be redirected to the following URL:<br />
     <br />
     <strong><?= $target_url ?></strong>
   </body>
 </html>
Now, if you want to set the previous page as the referrer, we'd have to handle it a bit differently. Also, you'll need to forcefully prepend "http://www.yoursite.com/out.php?s=" to all active hyperlinks on your pages.
 
Last edited:
wow that was exactly what I was looking for my man. Perfect. Now I just need your help finding out how to prepend all hyperlinks on mediawiki and using the previous page as a referrer. I really appreciate it!
 
Back
Top