make links look like they go to my own site.

Discussion in 'PHP' started by login, Mar 14, 2008.

  1. #1
    I have a site with a lot of outgoing links to a site i am affiliate at. I would like to make all that links look like the goes to my own site.

    Example.

    This is what I have now:
    example.com/1/711-37038-2478-0/1?AID=10434577&PID=2934555&loc=http%3A%2F%2Fexample.com%2F-bass-thumb-orig_W0QQitemZ360039999477QQcmdZViewItemQQssPageNameZRSS%3AB%3ASRCH%3AUS%3A102

    This is somehow how I want it to be:
    mysite.com/item/bass-thumb-orig_W0QQitemZ360039999477

    Thanks. Green rep to answers :)
     
    login, Mar 14, 2008 IP
  2. AsHinE

    AsHinE Well-Known Member

    Messages:
    240
    Likes Received:
    8
    Best Answers:
    1
    Trophy Points:
    138
    #2
    Well. An example of .htaccess file
    
    RewriteEngine On
    RewriteBase /item/
    
    RewriteCond %{REQUEST_FILENAME} !-f
    
    RewriteRule (.+?)/$	/item/index.php?item=$1 [L,QSA]
    RewriteRule (.+?)$	/item/index.php?item=$1 [L,QSA]
    
    Code (markup):
    It will redirect all requests like /item/bass-thumb-orig_W0QQitemZ360039999477/
    /item/index.php and in this script you will have $_GET['item'] variable value of
    "bass-thumb-orig_W0QQitemZ360039999477"

    After that you can chose where to send your visitor either selecting necessary url from database or just use this value as a part or url like
    
    header("Location: http://example.com/item.php?item=".$_GET['url']");
    
    PHP:
     
    AsHinE, Mar 14, 2008 IP
    login likes this.
  3. login

    login Notable Member

    Messages:
    8,849
    Likes Received:
    349
    Best Answers:
    0
    Trophy Points:
    280
    #3
    Sorry, I dont understand what you mean.

    When I point the mouse pointer on :
    example.com/1/711-37038-2478-0/1?AID=10434577&PID=2934555&loc=http%3A%2F%2Fexample.com%2F-bass-thumb-orig_W0QQitemZ360039999477QQcmdZViewItemQQssPageNameZRSS%3AB%3ASRCH%3AUS%3A102
    will the browser then show:
    mysite.com/item/bass-thumb-orig_W0QQitemZ360039999477
    ?

    This is my current .htaccess:

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    # END WordPress

    How should I add your code?
     
    login, Mar 14, 2008 IP
  4. AsHinE

    AsHinE Well-Known Member

    Messages:
    240
    Likes Received:
    8
    Best Answers:
    1
    Trophy Points:
    138
    #4
    Ok, in details.
    Create /item/ folder in root of your site.
    Put .htaccess file from my previous post there.
    Make a file index.php with the following contents:
    
    if ($_GET['url'] != "") header("Location: http://example.com/1/711-37038-2478-0/1?AID=10434577&PID=2934555&loc=http%3A%2F%2Fexample.com%2F-".$_GET['url']."QQcmdZViewItemQQssPageNameZRSS%3AB%3ASRCH%3AUS%3A102");
    else
    // redirect empty queries to homepage
     header("Location: http://mysite.com");
    
    PHP:
    After that any link to mysite.com/item/bass-thumb-orig_W0QQitemZ360039999477 will redirect your visitor to example.com/ with necessary url.

    Or maybe I did not understand your question.
    If you want to hide status line of browser when you hover over a link - it is a javascript question.
    If you want to show your site address and display contents of example.com - then use iframe or fetch other site content.
     
    AsHinE, Mar 14, 2008 IP
  5. login

    login Notable Member

    Messages:
    8,849
    Likes Received:
    349
    Best Answers:
    0
    Trophy Points:
    280
    #5
    Well. I want the SE`s to think that I link to my inner pages, but when clicked the links goes to site that I am affiliated to.
    Like in this site: chainsaw-store.com/Gas-Chainsaws/Poulan-Chainsaws
     
    login, Mar 14, 2008 IP
  6. Gonzo4u

    Gonzo4u Well-Known Member

    Messages:
    410
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    110
    #6
    With mod rewrite you can change the way your links will look, but for that you need to have an understanding of how .htaccess files work which AsHinE is trying to show.

    One more option is there of JavaScript from which you can make SE believe its your internal link, as SE spiders only href tag not the Javascript itself.

    Here how to do it.

    Eg:

    <a href="mysite.com/item/" onclick="window.location='http://www.externallinksite.com'+this.href; return false">External Link</a>

    Here the SE will spider href link only and will ignore JavaScript link. But you need to handle your internal link addresses provide in href, else SE spiders will get broken links.

    Other way of doing it is, you can make the pages of all your affiliate links and write an redirect code it that files for actual affiliate link location.

    eg. affiliate.php
    URL: mysite.com/affiliate.php

    Now write PHP header redirect of affiliate link in affiliate.php file.

    This techniques do work but requires labour work, so its better to use mod rewrite. Rewrite can change the way your link look, but they cannot get trigger on click event, as on click it will lead you to the link web server and .htaccess has no action on that.

    Gonzo
     
    Gonzo4u, Mar 14, 2008 IP
  7. AsHinE

    AsHinE Well-Known Member

    Messages:
    240
    Likes Received:
    8
    Best Answers:
    1
    Trophy Points:
    138
    #7
    Well, they are redirecteing users as I wrote:
    
    Location: http://rover.ebay.com/rover/1/711-37018-2978-0/1?AID=10420677&PID=2789618&SID=Gas+Chainsaws+Poulan+Chai&loc=http%3A%2F%2Fcgi.ebay.com%2FPOULAN-PRO-330-CHAINSAW-with-22-CHAINSAW-BAR-AND-CHAIN_W0QQitemZ110232742544QQcmdZViewItemQQssPageNameZRSS%3AB%3ASRCH%3AUS%3A101
    
    Code (markup):
    It is a part of response from server when I clicked this link
    
    http://chainsaw-store.com/item/POULAN-PRO-330-CHAINSAW-with-22-CHAINSAW-BAR-AND-CHAIN_W0QQitemZ110232742544
    
    Code (markup):
    I described how to do this in previous posts.
     
    AsHinE, Mar 14, 2008 IP
  8. stoli

    stoli Peon

    Messages:
    69
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    0
    #8
    As AsHinE has said what you want to do is create a new directory in the root of your website named 'item'. So you have mysite.com/item/.

    Into this 'item' directory put the following '.htaccess' file:
    RewriteEngine on
    RewriteRule ^([-a-zA-Z0-9_]*)/?$ index.php?id=$1
    
    Code (markup):
    Also put the following 'index.php' file into the 'item' directory:
    <?php
    
    // List links here - no comma on the end of the last one
    $links = Array(
                   'bass-thumb-orig_W0QQitemZ360039999477' => 'http://www.example.com/1/711-37038-2478-0/1?AID=10434577&PID=2934555&loc=http%3A%2F%2Fexample.com%2F-bass-thumb-orig_W0QQitemZ360039999477QQcmdZViewItemQQssPageNameZRSS%3AB%3ASRCH%3AUS%3A102',
                   'llama' => 'http://en.wikipedia.org/wiki/Llama',
                   'alpaca' => 'http://en.wikipedia.org/wiki/Alpaca'
                  );
    
    // If link recognised set it as the one to redirect to
    if (!empty($_GET['id']) && array_key_exists($_GET['id'], $links)) {
      $link = $links[$_GET['id']];
    }
    else {
      // No link recognised so default to your own home page
      $link = 'http://www.mysite.com';
    }
    
    // Send redirect header
    header("Location: $link");
    
    ?>
    PHP:
    Now any time you go to 'mysite.com/item/xyz' then you will get redirected the the address listed in 'index.php' for 'xyz'. If 'xyz' is not listed then you will go to your home page.

    There are three example links in 'index.php' to give you an idea of how to add your own. For example 'mysite.com/item/llama' will redirect to 'http://en.wikipedia.org/wiki/Llama'. You can add as many affiliate redirects as you like this way.

    You can then just update the anchor tags in your web site so instead of, for example:
    <a href="http://www.example.com/1/711-37038-2478-0/1?AID=10434577&PID=2934555&loc=http%3A%2F%2Fexample.com%2F-bass-thumb-orig_W0QQitemZ360039999477QQcmdZViewItemQQssPageNameZRSS%3AB%3ASRCH%3AUS%3A102">
    
    HTML:
    you put:
    <a href="/item/bass-thumb-orig_W0QQitemZ360039999477">
    
    HTML:
    Then the links appear to go to your site but actually redirect to the affiliate link.

    Many search engines will follow these redirects though, so if you don't want that to happen then stop them indexing anything in the 'item' directory by placing this 'robots.txt' file in the document root of your website:
    User-agent: *
    Disallow: /item/
    
    Code (markup):
    (If you have a robots.txt already then just add this directive to it).
     
    stoli, Mar 14, 2008 IP