织梦DedeCMS实现tag标签伪静态为id.html

织梦DedeCMS的tag标签系统默认是/tags.php?/tag标签/,不利于SEO优化,此教程教大家设置TAG标签页为伪静态,并且是单链接/id.html的形式。

链接形式

TAG标签页  /tags/9.html

TAG标签分页 /tags/9_2.html

PC端TAG伪静态实现教程

1、/tags.php 找到 18行

if(isset($tags[2])) $PageNo = intval($tags[2]);

在它下面加入

$tagid = (isset($tag) && is_numeric($tag)) ? intval($tag) : 0;
if(!empty($tagid))
{
    $row = $dsql->GetOne("SELECT tag FROM `#@__tagindex` WHERE id = {$tagid}");
    if(!is_array($row))
    {
        ShowMsg("系统无此标签,可能已经移除!","-1");exit();
    }
    else
    {
        $tag = $row['tag'];
        define('DEDERETAG', 'Y');
    }
}
else
{
    $tag = '';
}

如图
织梦DedeCMS实现tag标签伪静态为id.html

2、/include/taglib/tag.lib.php 找到 87行

$row['link'] = $cfg_cmsurl."/tags.php?/".urlencode($row['keyword'])."/";

改成

$row['link'] = $cfg_cmsurl."/tags/".$row['id'].".html";

3、/include/arc.taglist.class.php 找到 458行

$purl .= "?/".urlencode($this->Tag);

改成

if(!defined('DEDERETAG'))
{
    $purl .= "?/".urlencode($this->Tag);
}

继续找到

return $plist;

在它上面加入

if(defined('DEDERETAG'))
{
    $plist = preg_replace('/_(\d+).html/i','.html',$plist);
    $plist = preg_replace('/.html\/(\d+)\//i','_\\1.html',$plist);
}

4、TAG标签伪静态规则,根据自己网站的主机环境选择下面的规则

.htaccess (Apache)

RewriteEngine On
RewriteBase /
RewriteRule ^tags\.html$    tags\.php
RewriteRule ^tags/([0-9]+)\.html$    tags\.php\?\/$1 [L]
RewriteRule ^tags/([0-9]+)\.html$    tags\.php\?\/$1\/
RewriteRule ^tags/([0-9]+)_([0-9]+)\.html$    tags\.php\?\/$1\/$2
RewriteRule ^tags/([0-9]+)_([0-9]+)\.html$    tags\.php\?\/$1\/$2\/

Nginx

#TAG标签伪静态规则 Nginx
rewrite ^/tags\.html$    /tags.php;
rewrite ^/tags/([0-9]+)\.html$    /tags.php?\/$1;
rewrite ^/tags/([0-9]+)\.html$    /tags.php?\/$1\/;
rewrite ^/tags/([0-9]+)_([0-9]+)\.html$     /tags.php?\/$1\/$2;
rewrite ^/tags/([0-9]+)_([0-9]+)\.html$  /tags.php?\/$1\/$2\/;

web.config (iis7 iis8)

<rule name="tag首页">
    <match url="^tags.html$" ignoreCase="false" />
    <action type="Rewrite" url="tags.php" appendQueryString="false" />
</rule>
<rule name="tag列表">
    <match url="^tags/([0-9]+).html$" ignoreCase="false" />
    <action type="Rewrite" url="/tags.php?/{R:1}" appendQueryString="false" />
</rule>
<rule name="tag列表最后有左斜杠">
    <match url="^tags/([0-9]+).html$" ignoreCase="false" />
    <action type="Rewrite" url="/tags.php?/{R:1}/" appendQueryString="false" />
</rule>
<rule name="tag列表分页">
    <match url="^tags/([0-9]+)_([0-9]+).html$" ignoreCase="false" />
    <action type="Rewrite" url="/tags.php?/{R:1}/{R:2}" appendQueryString="false" />
</rule>
<rule name="tag列表分页最后有左斜杠">
    <match url="^tags/([0-9]+)_([0-9]+).html$" ignoreCase="false" />
    <action type="Rewrite" url="/tags.php?/{R:1}/{R:2}/" appendQueryString="false" />
</rule>

如需后台TAG标签管理里的TAG链接点击打开也是伪静态可这样改

织梦DedeCMS实现tag标签伪静态为id.html

打开 /dede/templets/tags_main.htm 找到 89行

<a href="../tags.php?/<?php echo urlencode($fields['tag']); ?>/" target="_blank">{dede:field.tag /}</a>

改成

<a href="../tags/{dede:field.id /}.html" target="_blank">{dede:field.tag /}</a>

完成。

SEO实战

别人都说seo已死,其实不然。百度seo优化提高企业网站综合排名

2021-12-15 13:33:35

SEO实战

头条上线PC网页版本,值得深思,头条搜索怎么做?

2021-12-15 13:43:31