Announcement

Collapse
No announcement yet.

How to change external links to internal links to do something before redirecting to the destination

Collapse
This is a sticky topic.
X
X
Collapse
First Prev Next Last
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • glennrocksvb
    replied
    Originally posted by moded View Post
    why when i follow the above steps i see blank page ...and were is the html code should add in redirect page ?
    When do you see the blank page? After clicking the link that should redirect to the external link? Or when loading the thread page itself? Please be more specific.

    Btw, this thread does not include the implementation of the redirect page itself. This is up to you. As I mentioned in the first, there are 2 possible ways to implement this. And the second way is how Yelp does it as shown in the screenshot I attached. But this thread does not show how to implement any of those ways. What this thread shows is how to change the external links in the posts to internal links in order for you to implement any of those 2 ways.

    Leave a comment:


  • moded
    replied
    Originally posted by glennrocksvb View Post
    FYI. I posted a bug report for this in http://tracker.vbulletin.com/browse/VBV-16703
    Yes i can't editing the post , when i do that my forum frozen

    Leave a comment:


  • moded
    replied
    why when i follow the above steps i see blank page ...and were is the html code should add in redirect page ?

    Leave a comment:


  • glennrocksvb
    replied
    Originally posted by glennrocksvb View Post
    Btw, there is a bug in vB where the backslash character "\" in the post goes away after posting or editing.
    FYI. I posted a bug report for this in http://tracker.vbulletin.com/browse/VBV-16703

    Leave a comment:


  • glennrocksvb
    commented on 's reply
    See post #7

  • glennrocksvb
    commented on 's reply
    What is this URL for?

  • glennrocksvb
    replied
    Originally posted by William View Post
    I think he is referring to the instructions: with these: (change $redirect_path with the appropriate path of the redirect URL)

    Would this be correct in his case: $redirect_path = "/test/22.html";
    That's correct. But I wonder what's in that 22.html file. It should have the code to redirect to the external URL passed in the querystring.

    Leave a comment:


  • moded
    replied
    http://shneler.com/vb/
    Last edited by moded; 11-15-2016, 02:46 PM.

    Leave a comment:


  • moded
    replied
    attached my original bbcode.php
    change to me and add redirect page http://shneler.com/test/22.html
    i will test and back to you quickly
    Attached Files

    Leave a comment:


  • William
    commented on 's reply
    I think he is referring to the instructions: with these: (change $redirect_path with the appropriate path of the redirect URL)

    Would this be correct in his case: $redirect_path = "/test/22.html";

    ???

  • glennrocksvb
    replied
    Could you elaborate on "my site not working"? What does not work? Saying "not working" does not help.

    Btw, there is a bug in vB where the backslash character "\" in the post goes away after posting or editing. I had to double the backslash to be able to show one. Make sure you copied the code in the first post correctly with backslashes preserved.

    Leave a comment:


  • moded
    replied
    for example this my goodbye page

    were should add in second HTML Code:?

    Leave a comment:


  • moded
    replied
    Hello,
    1: i try do that change this ( what i have in my
    /includes/vb5/template/bbcode.php )
    HTML Code:
            // standard URL hyperlink
            return "<a href="$url" target="_blank">$text</a>";
        }
    with these:

    HTML Code:
    $rightlink_host = parse_url($rightlink, PHP_URL_HOST);
    $forum_baseurl = vB::getDatastore()->getOption('frontendurl');
    $forum_host = parse_url($forum_baseurl, PHP_URL_HOST);        
    
    // if same host, then use the link directly
    if (vB5_String::stripos($rightlink_host, $forum_host) !== false) {
        return "<a href="$rightlink" target="_blank"" . ($is_external ? ' rel="nofollow"' : '') . ">$text</a>";
    }
    else { // link to your redirect page and pass the encoded external link
    
        $redirect_path = "/link.php?url="; // specify path of the redirect URL (exclude forum base url) including the querystring parameter name
    
        return "<a href="" . $forum_baseurl . $redirect_path . urlencode($rightlink) . "" target="_blank"" . ($is_external ? ' rel="nofollow"' : '') . ">$text</a>";
    }
    Clear system cache ... after that my site not working !
    2: can you please more clarification about this (change $redirect_path with the appropriate path of the redirect URL)
    Thank You

    Leave a comment:


  • How to change external links to internal links to do something before redirecting to the destination

    There are cases when you want external links posted in your forum to go through your page first before redirecting to the external URL. Most sites do this. Here are the reasons why you would want to do this:

    1. To track the clicks to the external links.
    2. To display an interstitial page to inform/warn user that they are navigating away from your site.

    Click image for larger version  Name:	redirect-min.png Views:	1 Size:	14.3 KB ID:	1943

    See how Yelp does #2.
    Without further ado, here's how to do it.

    There are 2 parts to do this:
    • Creating the redirect page. This is only for #2 above. For #1, you're on your own. If you already have set it up, you can skip this)
    • Editing the php file to change the external links to point to the redirect page.

    Create the Redirect Page:

    1. Create a new page in Sitebuilder.
    2. Drag and drop a PHP module.
    Title: Redirecting... (or whatever you want)
    PHP Code: (Change 5000 milliseconds to whatever delay you want)
    PHP Code:
    $url = isset($_GET['url']) ? urldecode($_GET['url']) : '';
    if (
    $url) {
        echo 
    '<p>You are leaving this site and will be automatically redirected to <a href="' htmlspecialchars($url) . '" id="vbmodsthatrock-external-link" rel="nofollow" onclick="return redirect(this.href);">' htmlspecialchars($url) . '</a> in a moment.</p>
            <script>
                function redirect(url) {
                    location.replace(url);
                    return false;
                }
                // redirect to the external URL with a 5-second delay
                setTimeout(function() {
                    redirect(document.getElementById("vbmodsthatrock-external-link").href);
                }, 5000); // 5000 milliseconds = 5 seconds, change accordingly
            </script>'
    ;
    }
    else {
        echo 
    'Sorry, there is no link to redirect to. You must have followed an invalid link.';


    3. Save the page and fill out the page information.
    Save the page name: Redirecting... (or whatever you want to show up in the tab name)
    Save the page URL based on the page name: redirect (this is what you're going to use when editing the PHP file)
    Template option: Redirect Template


    Edit the PHP File:

    1. Logon to cPanel (or equivalent).
    2. Edit the following PHP file:
    Code:
    /includes/vb5/template/bbcode.php
    3. Change these:
    PHP Code:
    // standard URL hyperlink
    return "<a href=\"$rightlink\" target=\"_blank\"" . ($is_external ' rel="nofollow"' '') . ">$text</a>"

    with these: (change $redirect_path with the appropriate path of the redirect URL)
    PHP Code:
    $rightlink_host parse_url($rightlinkPHP_URL_HOST);
    $forum_baseurl vB::getDatastore()->getOption('frontendurl');
    $forum_host parse_url($forum_baseurlPHP_URL_HOST);        

    // if same host, then use the link directly
    if (vB5_String::stripos($rightlink_host$forum_host) !== false) {
        return 
    '<a href="$rightlink" target="_blank"' . ($is_external ' rel="nofollow"' '') . ">$text</a>";
    }
    else { 
    // link to your redirect page and pass the encoded external link

        // specify path of the redirect URL (exclude forum base url) including the querystring parameter name
        // this is the path you used when you created the redirect page in Sitebuilder
        
    $redirect_path "/redirect?url=";

        return 
    '<a href="' $forum_baseurl $redirect_path urlencode($rightlink) . '" target="_blank"' . ($is_external ' rel="nofollow"' '') . ">$text</a>";


    4. Clear system cache in AdminCP > Maintenance > Clear System Cache.


    Screenshot:

    Click image for larger version  Name:	redirect-page-min.png Views:	1 Size:	25.0 KB ID:	1963

    NOTE: Since this is a PHP hack, this change will be overwritten during upgrade. So you have to re-apply this change whenever you upgrade.
    Last edited by glennrocksvb; 10-02-2019, 02:45 PM. Reason: Updated code to escape "\" in posts to avoid bug in vB

Users Viewing This Page

Collapse

There is 1 user viewing this forum topic.

  • Guest Guest

Latest Posts

Collapse

Working...
X
Searching...Please wait.
An unexpected error was returned: 'Your submission could not be processed because you have logged in since the previous page was loaded.

Please push the back button and reload the previous window.'
An unexpected error was returned: 'Your submission could not be processed because the token has expired.

Please push the back button and reload the previous window.'
An internal error has occurred and the module cannot be displayed.
There are no results that meet this criteria.
Search Result for "|||"