好!欢迎访问迷津渡口 现在时间是: 天气 °C ~ °C

迷津渡口

越感到迷惑 越接近真理

PHP外链本地化及自动添加nofollow属性

做网站的都或多或少需要了解一点SEO的知识,在发文章的时候对于站外链接都想加上一个nofollow的属性,以防止本站的权重不流失,手动给每个链接增加nofollow有些费事,今天分享的PHP代码自动把非本站网址的链接加上nofollow属性。

首先添加下面代码到module.php

<?php
function content_nofollow($log_content, $domain)
{
    preg_match_all('/href="(.*?)" rel="external nofollow" /', $log_content, $matches);
    if ($matches) {
        foreach ($matches[1] as $val) {
            if (strpos($val, $domain) === false) {
                $log_content = str_replace('href="' . $val . '" rel="external nofollow"  rel="external nofollow" ', 'href="' . $val . '" rel="external nofollow"  rel="external nofollow"  rel="external nofollow" ', $log_content);
            }
        }
    }
    preg_match_all('/src="(.*?)"/', $log_content, $matches);
    if ($matches) {
        foreach ($matches[1] as $val) {
            if (strpos($val, $domain) === false) {
                $log_content = str_replace('src="' . $val . '"', 'src="' . $val . '" rel="external nofollow"', $log_content);
            }
        }
    }
    return $log_content;
}?>

然后到echo_log.php、page.php里替换<?php echo $log_content; ?>为下面代码

<?php echo content_nofollow($log_content,BLOG_URL);?>

另外一种方法是外链本地化

首先需要将下面的代码保留到redirect.php,并提交到网站根目录

<?php 
error_reporting(0);
$url = $_GET['url'];
header("Location:".$url);
?>

然后添加下面代码到module.php

<?php
function content_nofollow($log_content, $domain){
preg_match_all('/href="(.*?)"/', $log_content, $matches);
if ($matches) {
foreach ($matches[1] as $val) {
if (strpos($val, $domain) === false) {
$log_content = str_replace('href="'.$val.'"', 'href="'.BLOG_URL.'redirect.php/?url='.$val.'"', $log_content);
}}}
preg_match_all('/src="(.*?)"/', $log_content, $matches);
if ($matches) {
foreach ($matches[1] as $val) {
if (strpos($val, $domain) === false) {
$log_content = str_replace('src="' . $val . '"', 'src="' . $val . '" rel="external nofollow"', $log_content);
}}}
return $log_content;
}?>

最后到echo_log.php、page.php里替换<?php echo $log_content; ?>为下面代码

<?php echo content_nofollow($log_content,BLOG_URL);?>

完成后即可外链本地化了。


小指重新优化了外链本地化的方法,里面只有href才使用了外链本地化,src使用nofollow的方法,否则会出错哦!!!

小指亲测的啦^_^

点赞1
   支持一下
挤眼 亲亲 咆哮 开心 想想 可怜 糗大了 委屈 哈哈 小声点 右哼哼 左哼哼 疑问 坏笑 赚钱啦 悲伤 耍酷 勾引 厉害 握手 耶 嘻嘻 害羞 鼓掌 馋嘴 抓狂 抱抱 围观 威武 给力
 点赞
 签到
 表情
 图片
 代码
提交评论

清空信息
关闭评论
tlgwebsterny
 tlgwebsterny 2019-03-20 07:25回复
#142
<a href="http://www.akncmusic.com/adidas-prougeator-lz-trx-fg-sl-bon-march%C3%A9-kurpesc">adidas prougeator lz trx fg sl bon march茅</a> <a href="http://www.dystopianflix.com/ralph-lauren-dark-bl%C3%A5-sweater-vneck-vest-polos">ralph lauren dark bl氓 sweater vneck vest</a> <a href="http://www.getunladylike.com/herren-nike-air-max-90-rot-gr%C3%BCn-butye">herren nike air max 90 rot gr眉n</a> <a href="http://www.jesselyon.com/ralph-lauren-tracksuit-caqui-naranja-polou">ralph lauren tracksuit caqui naranja</a> <a href="http://www.kabukcuoglu.com/adidas-ultra-boost-p%C3%BArpura-mattress-chaussurese">adidas ultra boost p煤rpura mattress</a> <a href="http://www.karbasioun.com/nike-air-max-zero-qs-blu-line-scarpee">nike air max zero qs blu line</a>
tlgwebsterny http://www.tlgwebsterny.com/
cmcheechalk
 cmcheechalk 2019-03-19 12:06回复
#141
<a href="http://www.snifferwalk.com/nike-soccers-schuhe-grau-schuhei">nike soccers schuhe grau</a> <a href="http://www.fishmackerel.com/mujeres-air-max-90-blanco-zapatosp">mujeres air max 90 blanco</a> <a href="http://www.lauraenergy.com/kvinders-nike-free-tr-sort-gr%C3%B8n-skoi">kvinders nike free tr sort gr酶n</a> <a href="http://www.magellantt.com/nike-lunar-hypergamer-low-hvit-obuvq">nike lunar hypergamer low hvit</a> <a href="http://www.sportablecrew.com/mens-air-max-90-hyperfuse-orange-gold-shoesh">mens air max 90 hyperfuse orange gold</a> <a href="http://www.digisolnc.com/adidas-damian-lillard-blu-viola-scarpei">adidas damian lillard blu viola</a>
cmcheechalk http://www.cmcheechalk.com/
partnersspa
 partnersspa 2019-03-19 03:56回复
#140
<a href="http://www.germanxtube.com/nike-cortez-nylon-men-fur-green-orange-shoesj">nike cortez nylon men fur green orange</a> <a href="http://www.eugenesklyar.com/minnesota-vikings-new-era-2017-nfl-sport-knit-hath">minnesota vikings new era 2017 nfl sport knit</a> <a href="http://www.bamadu.com/hombres-asics-gel-kinsei-2-blanco-mettodasic-rojo-negro-zapatosl">hombres asics gel kinsei 2 blanco mettodasic rojo negro</a> <a href="http://www.gamekeyssale.com/adidas-predator-4-shoesk">adidas predator 4</a> <a href="http://www.aktuelresim.com/air-jordan-1-retro-high-r%C3%B8d-svart-obuvi">air jordan 1 retro high r酶d svart</a> <a href="http://www.myshoesonsale.com/adidas-climacool-ride-iv-menn-carbon-gr%C3%A5-male-obuvk">adidas climacool ride iv menn carbon gr氓 male</a>
partnersspa http://www.partnersspa.com/
martinmakeup
 martinmakeup 2019-03-18 22:04回复
#139
<a href="http://www.diplomabroad.com/nike-air-max-1-essential-hvid-bl%C3%A5-skoj">nike air max 1 essential hvid bl氓</a> <a href="http://www.trechadental.com/ralph-lauren-city-tote-bag-poloh">ralph lauren city tote bag</a> <a href="http://www.akhbarsanaye.com/lebron-13-blue-black-orange-shoesi">lebron 13 blue black orange</a> <a href="http://www.timxes.com/nike-kobe-11-nero-scarpej">nike kobe 11 nero</a> <a href="http://www.leadercheetah.com/air-jordan-1-rot-schuhej">air jordan 1 rot</a> <a href="http://www.arealleader.com/new-san-diego-padres-hat-hath">new san diego padres hat</a>
martinmakeup http://www.martinmakeup.com/
ycbrowsbeauty
 ycbrowsbeauty 2019-03-18 16:07回复
#138
<a href="http://www.supermarketes.com/nike-air-force-1-high-lila-wei%C3%9F-scarpee">nike air force 1 high lila wei脽</a> <a href="http://www.texastribal.com/jordan-8-grigio-obuvc">jordan 8 grigio</a> <a href="http://www.donareseguros.com/jordan-7-gris-fuschia-scarpea">jordan 7 gris fuschia</a> <a href="http://www.frozentissue.com/kaufen-nike-roshe-ld-1000-sp-chaussuresg">kaufen nike roshe ld 1000 sp</a> <a href="http://www.lampenloft.com/femminile-nike-kyrie-1-viola-verde-kurpese">femminile nike kyrie 1 viola verde</a> <a href="http://www.notasoficina.com/air-jordan-28-rosa-svart-obuva">air jordan 28 rosa svart</a>
ycbrowsbeauty http://www.ycbrowsbeauty.com/
kathimartuza
 kathimartuza 2019-03-17 06:23回复
#137
<a href="http://www.advertiseguns.com/nike-adam-jones-youth-white-limited-jersey-24-nfl-road-cincinnati-bengals-nflw">nike adam jones youth white limited jersey 24 nfl road cincinnati bengals</a> <a href="http://www.bodhiboxers.com/nike-free-run-5.0-v2-tiffany-bleu-island-schuheg">nike free run 5.0 v2 tiffany bleu island</a> <a href="http://www.chateaudefous.com/nike-hypervenom-mid-todas-blanco-scarpeg">nike hypervenom mid todas blanco</a> <a href="http://www.prinslabs.com/nike-shox-tlx-dam%C3%A4nner-kurpesf">nike shox tlx dam盲nner</a> <a href="http://www.solarishelp.com/air-jordan-future-orange-gris-schuheg">air jordan future orange gris</a> <a href="http://www.tioneo.com/kyrie-1-herre-basketballe-sko-jordans-schuheb">kyrie 1 herre basketballe sko jordans</a>
kathimartuza http://www.kathimartuza.com/
smokeyhollowfarm
 smokeyhollowfarm 2019-03-17 02:51回复
#136
<a href="http://www.dissertationsverlag.net/jordan-13-oro-dmp-obuvd">jordan 13 oro dmp</a> <a href="http://www.divxcompare.net/zx-flux-todas-rojo-amarillo-chaussuresa">zx flux todas rojo amarillo</a> <a href="http://www.dnacf.net/air-max-1-og-sport-rot-butya">air max 1 og sport rot</a> <a href="http://www.doresdecabeca.net/nike-tiempo-legend-6-schwarz-orange-scarpef">nike tiempo legend 6 schwarz orange</a> <a href="http://www.dorothygrant.net/nike-free-flyknit-5.0-bleu-camo-butyf">nike free flyknit 5.0 bleu camo</a> <a href="http://www.dotjewelers.net/air-max-2014-bl%C3%A5-hvid-butyf">air max 2014 bl氓 hvid</a>
smokeyhollowfarm http://www.smokeyhollowfarm.net/
batatastudio
 batatastudio 2019-03-15 00:56回复
#135
<a href="http://www.ptsbarwinslow.com/nike-air-max-95-alle-r%C3%B8d-skoh">nike air max 95 alle r酶d</a> <a href="http://www.sarhallafk.com/converse-tutti-star-chuck-taylor-high-top-nero-scarpei">converse tutti star chuck taylor high top nero</a> <a href="http://www.philippikus.com/adidas-tubular-runner-bianca-nero-scarpej">adidas tubular runner bianca nero</a> <a href="http://www.pngoilgas.com/derek-carr-official-jersey-nflh">derek carr official jersey</a> <a href="http://www.goficarwash.com/department-stores-that-carry-coach-handbags-coachh">department stores that carry coach handbags</a> <a href="http://www.getairtijuana.com/acquistare-nike-air-huarache-nero-scarpei">acquistare nike air huarache nero</a>
[url=http://www.batatastudio.com/]batatastudio[/url]
manglammovers
 manglammovers 2019-03-14 19:53回复
#134
<a href="http://www.zeraxia.com/adidas-ultra-boost-schwarz-3.0-schuhei">adidas ultra boost schwarz 3.0</a> <a href="http://www.turisim.com/adidas-samba-fl%C3%A5den-bl%C3%A5-and-hvid-skoh">adidas samba fl氓den bl氓 and hvid</a> <a href="http://www.sybelite.com/nike-mens-baltimore-ravens-customized-white-game-jersey-nfli">nike mens baltimore ravens customized white game jersey</a> <a href="http://www.lemodemo.com/rosa-adidas-sko-gazelle-obuvk">rosa adidas sko gazelle</a> <a href="http://www.fskanglipu.com/cream-colored-coach-purse-coachh">cream colored coach purse</a> <a href="http://www.tekmenu.com/maschio-nike-blazer-bianca-scarpej">maschio nike blazer bianca</a>
manglammovers http://www.manglammovers.com/
goficarwash
 goficarwash 2019-03-14 16:06回复
#133
<a href="http://www.cherylblogs.com/m%C3%A6nd-under-armour-curry-one-fluorescent-gr%C3%B8n-orange-skok">m忙nd under armour curry one fluorescent gr酶n orange</a> <a href="http://www.livefreshpbc.com/air-jordan-3-true-blau-2011-schuheh">air jordan 3 true blau 2011</a> <a href="http://www.bacaiptek.com/nike-huarache-trainers-black-shoesk">nike huarache trainers black</a> <a href="http://www.socabets.com/kyrie-1-deceptive-r%C3%B8d-skol">kyrie 1 deceptive r酶d</a> <a href="http://www.sgeventportal.com/nike-lab-air-max-270-jade-svart-hvit-obuvk">nike lab air max 270 jade svart hvit</a> <a href="http://www.isimsizsevda.com/maschio-salomon-s-lab-fellcross-rosso-arancia-scarpei">maschio salomon s lab fellcross rosso arancia</a>
goficarwash http://www.goficarwash.com/
顶部留言底部
 00:00/00:00
我想和你虚度时光 - 花房姑娘(9)
  1. 我想和你虚度时光
  2. 花房姑娘
  3. 恋恋风尘
  4. 我喜爱一切不彻底的事物
  5. 我的心里是满的
  6. Long Way
  7. 给少年的歌
  8. 晴日共剪窗
  9. 天上的月你的脸