preetham Posted July 15, 2013 Share Posted July 15, 2013 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. Quote Link to comment Share on other sites More sharing options...
dalecosp Posted July 15, 2013 Share Posted July 15, 2013 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 ... Quote Link to comment Share on other sites More sharing options...
cyberRobot Posted July 16, 2013 Share Posted July 16, 2013 The following plug-in looks to do what you want: http://wordpress.org/plugins/bwp-external-links/ Quote Link to comment Share on other sites More sharing options...
Solution 2260419 Posted July 17, 2013 Solution Share Posted July 17, 2013 (edited) 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 July 17, 2013 by 2260419 Quote Link to comment Share on other sites More sharing options...
preetham Posted July 17, 2013 Author Share Posted July 17, 2013 (edited) @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 July 17, 2013 by preetham Quote Link to comment Share on other sites More sharing options...
preetham Posted July 17, 2013 Author Share Posted July 17, 2013 (edited) @2260419 This works like a charm.. Thanks a ton Edited July 17, 2013 by preetham Quote Link to comment Share on other sites More sharing options...
2260419 Posted July 17, 2013 Share Posted July 17, 2013 @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 Quote Link to comment Share on other sites More sharing options...
preetham Posted July 18, 2013 Author Share Posted July 18, 2013 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? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.