随着越来越多的站长开始重视搜索引擎优化(SEO),他们对rel="nofollow"属性的关注也逐渐增多。然而,百度编辑器UEditor并不自带rel="nofollow"功能,这导致在引入其他站点URL链接时,可能会出现蜘蛛流失的情况,从而降低自己网站的权重。本文将教您如何修改UEditor,使其生成的链接自动带有rel="nofollow"标签。
### 修改步骤 #### 第一步:编辑link.html文件 找到/core/extend/ueditor/dialogs/link/link.html文件,并定位到第81行。原始代码如下:

'href' : href,
'target' : $G("target").checked ? "_blank" : '_self',
'title' : $G("title").value.replace(/^\\s+|\\s+$/g, ''),
'_href':href
    
将其修改为以下内容,在其中添加rel="nofollow"属性:

'href' : href,
'target' : $G("target").checked ? "_blank" : '_self',
'title' : $G("title").value.replace(/^\\s+|\\s+$/g, ''),
'rel': 'nofollow',
'_href':href
    

#### 第二步:编辑ueditor.config.js文件 接下来,找到/core/extend/ueditor/ueditor.config.js文件,并定位到第370行。原始代码如下:

a:      ['target', 'href', 'title', 'class', 'style','name','id'],
abbr:   ['title', 'class', 'style'],
abbr:   ['title', 'class', 'style'],
area:   ['shape', 'coords', 'href', 'alt'],
    
将其修改为以下内容,确保rel属性被允许使用:

a:      ['target', 'href', 'title', 'class', 'style','name','rel','id'],
abbr:   ['title', 'class', 'style'],
abbr:   ['title', 'class', 'style'],
area:   ['shape', 'coords', 'href', 'alt'],
    

### 测试与效果 完成上述两个文件的修改后,您可以进入网站后台测试添加链接的功能。如果一切正常,生成的链接将会自动带有rel="nofollow"属性。以下是演示效果截图: pbootcms百度编辑器UEDITOR给超链接默认添加rel="nofollow"标签 通过以上操作,您的UEditor编辑器将能够更好地支持SEO优化,有效避免因外部链接导致的权重流失问题。希望这篇文章能帮助到正在为此困扰的站长们!