Last update at :2024-01-18,Edit by888u
This tutorial comes from pc6a. We have streamlined and modified it so that it can Convert automatic external links to "your URL/go/". It is very convenient, and it is automatically converted by PHP. It does not store data and does not take up space on the server. Most of the code is directly quoted. Novice’s tutorials are more suitable for pure novices like me.
1. Add encryption code
First open the functions.php file in the theme folder and add the following code as needed
1. Convert the external link of the article to the internal link:
// Article external link jump pseudo-static version add_filter('the_content','link_jump',999); function link_jump($content){ preg_match_all('//',$content,$matches); if($matches){ foreach($matches[2] as $val){ if(strpos($val,'://')!==false && strpos($val,home_url())===false && !preg_match('/\.(jpg|jepg|png|ico|bmp| gif|tiff)/i',$val) && !preg_match('/(ed2k|thunder|Flashget|flashget|qqdl):\/\//i',$val)){ $content=str_replace("href=\"$val\"", "href=\"".home_url()."/go/".base64_encode($val)."\" rel=\"nofollow\" target =\"_blank\"",$content); } } } return $content; }2. Comment external link to internal link:
//Redirect commenter link function commentauthor($comment_ID = 0) { $url = get_comment_author_url( $comment_ID ); $author = get_comment_author( $comment_ID ); if ( empty( $url ) || 'http://' == $url ) { echo $author; } else { if (!preg_match(home_url(),$url)) { echo "$author" ; } else { echo "$author"; } } }2. Create go jump file
Create the go.html file in the root directory of the website and write the following code in the file:
3. Modify pseudo-static
If it is a pagoda directly on the website-settings-pseudo-static, add the following code to the last line
NGINX code:
rewrite ^/go/(.*)$ /go.html?url=$1 last;Apache code:
RewriteRule ^go/(.*)$ /go.html?url=$1 [L]4. Other instructions
- www.zhujizhen.com is Xiaobai’s domain name, remember to change it to your own;
- The go in /go/ can be modified to what you like;
- Remember to exclude /go/ in robots.txt;
Recommended site search: foreign PHP host, Taiwan host, domain name registration website, overseas server, US ASP space, server rental, mainland China agent IP, Hong Kong's best virtual host, Wanwang domain name registration official website, IP rental,
p>
发表评论