将站点中的所有链接重定向到重定向页面

时间:2015-01-19 08:39:03

标签: php .htaccess

我不知道这个问题的正确标题。 昨天我发现这个网站http://www.hyper-hippo.net/ 每个我点击帖子页面中的链接,链接转到重定向页面。它是如何工作的? 该网站在博客中创建它。 也许脚本和adf.ly一样,但是怎么样?

如何制作重定向页面,当地址栏类型?url=www.google.com将转到重定向页面时,该链接将转到google.com。

4 个答案:

答案 0 :(得分:2)

要执行此操作,请按以下步骤操作:

1。链接是使目标空白。

示例:

在新窗口或标签页中打开链接:

<a href="alvinshortener.com/index.php?url=www.google.com" target="_blank">Visit </a>

在index.php里面写:

<?php
if(isset($_GET['url'])){
header("Location: $_GET['url']");
}
?>

答案 1 :(得分:1)

也许我可以帮忙。 在ASP.NET中,我们使用AdRotator重定向页面。 这意味着您可以拥有一个页面,例如&#34; hyper-hippo.net&#34;使用adRotator构建。

这是一个例子:在ASP.NET中

$sql = mysql_query("SELECT * FROM sites WHERE sites ='" . $_POST["sitess"] . "'");
$id = mysql_fetch_array($sql);

<p><a href="ad1.xml" target="_blank">View XML file</a></p>

这是PHP的另一个例子:

$ads = array("ad code goes here", "more ad code", "more ad code");
shuffle($ads);
print $ads;

这是HTML中的另一个

<div id="rotator">
    <img class="ad" src="#" />
    <img class="ad" src="#" />
    <img class="ad" src="#" />
    <img class="ad" src="#" />
</div>

这是JS + HTML中的另一个

<div id="rotator">
    <img class="ad" src="ad_banner1.png" />
    <img class="ad" src="ad_banner2.png" />
    <img class="ad" src="ad_bannerN.png" />
</div>

<script type="text/javascript">// Fisher-Yates Algorithm written by Gio Borje <http://www.giocc.com>
(function() {
    // Get the list of ads on your site
    var ads = document.getElementsByClassName("ad");

    // Used for swapping in the algorithm
    var tmp;

    // Random index to swap with
    var randomIdx;

    // Random sorting algorithm
    for (var i = 0; i < ads.length - 1; i++) {
        randomIdx = i + 1 + Math.floor(Math.random() * (ads.length - i));
        tmp = ads[randomIdx].src;
        ads[randomIdx].src = ads[i].src;
        ads[i].src = tmp;
    }
}​)();</script>

我希望这个帮助!!!

答案 2 :(得分:0)

您可以在html的head部分使用meta标签,例如

<meta http-equiv="refresh" content="0; url=http://example.com/" />

答案 3 :(得分:0)

您可以使用header()这样的功能:

if (isset($_GET['url'])){ //check if URL is set in adress
    $url = htmlspecialchars(filter_input(INPUT_GET, 'url'), ENT_COMPAT, 'UTF-8'); // XSS attack prevention 
    if(strpos($url,'http://')>0 ||strpos($url,'https://')>0){ // check if the address is http://example.com or example.com
        header('Location: '.$url.'/'); // redirection code of php
    } else {
        header('Location: http://'.$url.'/');
    }
}