Wood Chen

SEO: Handling External Links

0 comments30 views50 words

This post was translated from Chinese by AI. If anything reads oddly, the Chinese original is authoritative. 中文原文

This method works for websites built with WordPress or other platforms. Some of the information comes from Zhang Ge's blog: https://zhang.ge/5086.html

Step 1: Create a go.php file in the website's root directory with the following content:

 384 ||
    strpos($_SERVER['REQUEST_URI'], "eval(") ||
strpos($_SERVER['REQUEST_URI'], "base64")) {
@header("HTTP/1.1 414 Request-URI Too Long");
@header("Status: 414 Request-URI Too Long");
@header("Connection: Close");
@exit;
}
//Get the full input from QUERY_STRING, then extract everything after url= for better compatibility
$t_url = preg_replace('/^url=(.*)$/i','$1',$_SERVER["QUERY_STRING"]);
 
//Define custom external links here, for example: /go/woodchen redirects to https://woodchen.ink
if($t_url=="woodchen" ) {
   $t_url="https://woodchen.ink";
} elseif($t_url=="baidu") {
   $t_url="https://www.baidu.com/";
}
 
//Process the input
if(!empty($t_url)) {
    //Check whether the value is encoded
    if ($t_url == base64_encode(base64_decode($t_url))) {
        $t_url =  base64_decode($t_url);
    }
    //Validate the value as a URL
    preg_match('/^(http|https|thunder|qqdl|ed2k|Flashget|qbrowser):\/\//i',$t_url,$matches);
if($matches){
    $url=$t_url;
    $title='页面加载中,请稍候...';
} else {
    preg_match('/\./i',$t_url,$matche);
    if($matche){
        $url='http://'.$t_url;
        $title='页面加载中,请稍候...';
    } else {
        $url = 'http://'.$_SERVER['HTTP_HOST'];
        $title='参数错误,正在返回首页...';
    }
}
} else {
    $title = '参数缺失,正在返回首页...';
    $url = 'http://'.$_SERVER['HTTP_HOST'];
}
?>

<?php echo $title;?>

 
 页面加载中,请稍候...  

Step 2: Add rewrite rules

  • Nginx:

    # External link redirect rewrite
    rewrite ^/go/(.*)$ /go.php?url=$1 last; #Check the actual path to go.php; the default is the website's root directory
    
  • apache:

    RewriteRule ^go/(.*)$ /go.php?url=$1 [L]
    

Last updated 2024-01-14

Related posts

Comments 0