Jump to content

redirect all external links thru my website.


preetham
Go to solution Solved by 2260419,

Recommended Posts

Hello,

 

This is my first post here, i am really hoping to get some solution here.

 

I had technical difficulty building my website.

 

My Requirement, (i'm using wordpress)

 

When i post an external link say "www.external.com".

I want it to be automatically converted to something like this

"www.mysite.com/redirect.php?www.external.com".

 

Later depending on which site is "external" i will edit id and redirect.

 

Can anyone help me with this.

 

Link to comment
Share on other sites

You might do it via Javascript after page load.  Obviously, it can be done from PHP as well; you'd have to know something about WordPress internals (and, obviously, PHP).

I don't know much about WordPress, though ... seems like I had an installation once, but I don't remember playing around with it ...

Link to comment
Share on other sites

  • Solution

you can try using the classic script to anonymize links. I have copied one, just change "http: //example.dev/" with your url. and the variable "url" if you want. eg "http:// yourdomain.com/redirect.php?url ="

 

javascript.zip

 

then put this code in your file "footer.php" of your template.

<!--script at the end of the body-->
<script src="http://example.dev/link_to_this_javascript.js" type="text/javascript"></script>
<script type="text/javascript">
//name of the sites that you want to exclude. only the name.
protected_links = "myspace,ebay";
redirect_refer();
</script>
<!--script at the end of the body-->

and finally, create a file called "redirect.php" in your root directory with the code:

//get the link
$str = $_GET['url'];

if ($str == '') {
//if the variable URL link is empty. eg ".../redirect.php?url=" or ".../redirect.php" then redirects to home.
	header('Location: http://example.dev/');
} else {
//otherwise redirects the external site.
	header('Location: '.$str);
}

after this, all you will see links like this:

http://example.dev/redirect.php?url=http://forums.phpfreaks.com/topic/280170-redirect-all-external-links-thru-my-website/
Edited by 2260419
Link to comment
Share on other sites

@2260419

 

THanks for your reply.

 

Now, where should i put in the javascript ?

 

I am using wordpress 

 

 

Should i put in /wp-includes/js   ?

 

 

Also, i am facing an issue in redirect.php part. 

 

 

please read this thread.

http://forums.phpfreaks.com/topic/280216-remove-new-line-from-encoded-url-string/

Edited by preetham
Link to comment
Share on other sites

@2260419

 

THanks for your reply.

 

Now, where should i put in the javascript ?

 

I am using wordpress 

 

 

Should i put in /wp-includes/js   ?

 

 

Also, i am facing an issue in redirect.php part. 

 

 

please read this thread.

http://forums.phpfreaks.com/topic/280216-remove-new-line-from-encoded-url-string/

 

you can put the javascript file anywhere, just make sure to change the link in the code of the footer.php of your template.

http://example.dev/link_to_this_javascript.js
Link to comment
Share on other sites

 

you can put the javascript file anywhere, just make sure to change the link in the code of the footer.php of your template.

http://example.dev/link_to_this_javascript.js

 

 

Thanks.

 

I have implemented it and it works just fine.

 

However, i have one thing to take care of, i.e , i want all these external links to open in new window.

 

Can it be done in same js or create new one?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.