Replace/redirect out going links!

They have: 4 posts

Joined: Apr 2004

hi guys... here's a question about php.
I use WordPress (a php based bloggin script)

i have thousands of posts/articles,

one thing i have noticed is havin too may out going links on a page drains your page rank. I dont like this . I have a lot (too many to fix manually) of out going links to diffenert websites from many articles as you would imagine.

I was wondering if there was a way to redirect all "out going" links w/ a redirect script on the fly.

for example .... http://mysite.com/post1.com has an out going links to http://google.com

i want that link to be http://mysite.com/redirect.php?url=http://google.com or somthing along thoose lines.

I would imagine it could be done by a simle find and replace snippet in php...

say find "http://" and replace it with "http://mysite.com/redirect.php?url="

but im a noob to php and dont know how (if) that would work, since wordpress is sorta like a CMS.

at any rate, DO you think its possible by SSI... This would be much earier for me, if you could lead me the correct direction .

Anyway, thanks for your time. Now dont just click the back button on the browser and loose your self in the black hole of cyber space..... POST SOMTHING

Busy's picture

He has: 6,151 posts

Joined: May 2001

Quote: i want that link to be http://mysite.com/redirect.php?url=http://google.com or somthing along thoose lines.

That could be done very easily. The redirect.php page would just have something like:

<?php
header
("$url");
?>

or if you wanted to track the redirected links add that on the page too, add the link ($url) to the database (be sure to validate the url and strip any nasties), just don't output (print to screen) anything before the header() function or you'll get an error

To add the http://mysite.com/redirect.php?url= bit you could modify the database contents, or just add the variable to the links, something like:

$add_url = "http://mysite.com/redirect.php?url=";

then in the page, would be something like "><?linkname?> and just add the above into it, like so <?=link?>"><?=linkname?>

I've never used wordpress so am not sure how the things coded, the above is standard PHP

He has: 57 posts

Joined: Apr 2005

Yeah, but actually, the redirect.php file should look like:

<?php
$url
= $_GET['url'];
header('Location: ' . $url);
?>

That will send the user to whatever is entered for url=. It should be pretty easy to change all of your outgoing links, but I too am unfamiliar with WordPress, otherwise I would tell you what code to change. I have done this exact thing with phpBB, does WordPress have some sort of code that you use in posts (like phpBB's bbcode)? So long as it does have such a thing, once again, it should be very easy to do what you are trying to do.

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.