How to remove paramaters from URL with HTACCESS

Discussion in 'Programming' started by jasonwilks, Feb 22, 2013.

  1. #1
    Hello all, I need help!

    I am implementing the facebook like button across all my pages (1000+ pages), and specified this for the og:url meta tag:
    <meta property="og:url" content="<?php echo curPageURL();?>" />
    I have a PHP script at the top of each page to draw the current URL to that meta tag. This is the script by the way:

    <?php
    function curPageURL() {
    $pageURL = 'http';
    if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
    $pageURL .= "://";
    if ($_SERVER["SERVER_PORT"] != "80") {
    $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
    } else {
    $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
    }
    return $pageURL;
    }
    ?>

    Then I use this PHP code/og meta tag to draw out the current URL of each page to the facebook like buttons across all the pages nicely.

    That works all fine and dandy. The problem is, is that when someone clicks on a Like button, then in facebook i saw the correct page liked, but when i click on the link there in FB, the link is what is specified in the code with some odd facebook querystring appended to it. For example:

    The page that i like is http://www.mydomain.com/path/to/the/page

    When i clicked on the liked link in facebook, the url is: http://www.mydomain.com/path/to/the/page?fb_action_ids=#####&fb_action_types=og.likes&fb_source=timeline_og&action_object_map={"###"%###}&action_type_map={"###"%3A"og.likes"}&action_ref_map=[]

    Then when someone in facebook clicks the link, it takes them to that long whacky URL with a whole new facebook Like button associated with it, and even worse it has a whole new URL page for the facebook comment system as well screwing that up as well.

    So as you can see the problem here, I assume there is something I can use in the HTACCESS file to block all instances of ?fb_action_ids=blah-blah-blah-blah out of the URLs, so it just loads the original URL and not all the facebook stuff in the URL!

    Thanks for any input on this!

     
    jasonwilks, Feb 22, 2013 IP
  2. jasonwilks

    jasonwilks Well-Known Member

    Messages:
    65
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    111
    #2
    Ok I found something elsewhere that looks like this in HTACCESS:

    Options +FollowSymlinks
    RewriteEngine On
    RewriteCond %{QUERY_STRING} ^(.*&)?fb_action_ids=
    RewriteRule ^(.*)$ $1?%1 [R=301]

    This is the closest thing I found so far that somewhat worked. The problem is, is that it puts the server address in there that I do not need, with that code, now when I click a link that looks like this:

    http://www.example.com/directory/page.html?fb_action_ids=339169019535306&fb_action_types=og.likes&fb_source=timeline_og&action_object_map=%7B%22339169019535306%22%3A211629772316872%7D&action_type_map=%7B%22339169019535306%22%3A%22og.likes%22%7D&action_ref_map=%5B%5D

    It goes to this:

    http://www.example.com/home/user/public_html/example.com/directory/page.html

    It does correctly remove the ?fb_action_ids= crap out, but I need the bolded stuff above removed as well!

    I really just want it to go to this:

    http://www.example.com/directory/page.html

    Any help any one?
     
    jasonwilks, Feb 22, 2013 IP
  3. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #3
    The trick is not to use what you are trying.
    Use the like button to set your urls
    <?php  echo "http://" . $_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']; ?>
    PHP:
     
    MyVodaFone, Feb 23, 2013 IP