Home > Article > CMS Tutorial > How dedecms implements pseudo-static throughout the site
The whole site of DedeCms is pseudo-static, which is to facilitate management and SEO. DedeCms generates static html files by default, which is very friendly to optimization, but there are still some pages. It is in a dynamic form (such as Tag page, website content search page, DedeCms Q&A page, etc.). In order to make these pages better included by search engines, pseudo-static needs to be made. Although the DedeCms system can generate static HTML file, but if the amount of content updated every day is particularly large, generating html files will also become a burden on the system and manpower, so it can also be made into a pseudo-static form, thus eliminating the need for tedious generation of html files.
Make the entire DedeCms site static, which requires the support of the mod_rewrite pseudo-static module. As long as the webmaster is proficient in .htaccess regular expressions, he can make the entire dede website static, which is more in line with search engines and can also avoid repeated URLs. DedeCms full-site pseudo-static configuration is a bit troublesome, mainly because we need to manually modify the source code. The organizing steps are as follows:
1. First, enable the pseudo-static function of the site. Log in to the dede administrator backend->System->System Basic Parameters->Core Settings->Select "Yes" whether to use pseudo-static.
2. Modify the source program to achieve pseudo-static homepage, pseudo-static channel page, pseudo-static list page, and pseudo-static article page. This process is more complicated and is not as good as other PHP open source programs. Simple.
3. Create and write .htaccess and .htaccess file rules and upload them to the installation directory of DedeCms.
DedeCms full-site pseudo-static tutorial: including list|article|Q&A|search|TAG pseudo-static rules:
1. Whether the website server and website space support it Pseudo-static:
This is particularly important, or all settings will not work. If your website uses a server, you can set it up yourself. If it is a space, you can ask the IDC service provider customer service to see if it supports pseudo-static (general spaces support pseudo-static). Apache server pseudo-static is relatively simple, just add the corresponding pseudo-static rules directly to the .htaccess file; and to implement pseudo-static on IIS server, you need to load the Rewrite component and then configure the httpd.ini file.
2. Turn on DedeCMS pseudo-static:
1) DedeCms backend - system parameters - core settings - whether to use pseudo-static: select "Yes";
2) If you enable the DedeCms question and answer module, in the background - system parameters - module settings - whether to use Rewrite: select "Yes";
3) When creating a column or adding columns in batches , column list options: select "Use dynamic pages"; when adding a new article, publishing options: select "dynamic browsing only". Similarly, you can also change their templates so that they default to these two values, once and for all. The modification method is very simple, the method is as follows:
Find the background file: /dede/templets/catalog_add.htm Modify the default "Use dynamic page" when adding columns
<td height="26" style="padding-left:10px;">栏目列表选项:</td> <td><input type='radio' name='isdefault' value='1' class='np' checked="checked" />链接到默认页 <input type='radio' name='isdefault' value='0' class='np' />链接到列表第一页 <input type='radio' name='isdefault' value='-1' class='np' />使用动态页</td>
Change to:
<td height="26" style="padding-left:10px;">栏目列表选项:</td> <td><input type='radio' name='isdefault' value='1' class='np' />链接到默认页 <input type='radio' name='isdefault' value='0' class='np' />链接到列表第一页 <input type='radio' name='isdefault' value='-1' checked="checked" class='np' />使用动态页</td>
Found the background file: /dede/templets/article_add.htm Modify the default "dynamic browsing only" when adding articles
<td width="90">发布选项:</td> <td width="379"><input name="ishtml" type="radio" class="np" value="1" checked="1" />生成HTML <input type="radio" name="ishtml" class="np" value="0"/>仅动态浏览 </td>
Changed to:
<td width="90">发布选项:</td> <td width="379"><input name="ishtml" type="radio" class="np" value="1" />生成HTML <input type="radio" name="ishtml" class="np" value="0" checked="1"/>仅动态浏览 </td>
4) If the website already has generated static columns or article HTML, you only need to execute the following statement in the background-system-SQL command line tool:
update dede_arctype set isdefault=-1; update dede_archives set ismake=-1;
Note: dede in the command is the data table prefix when the website is installed. Replace according to actual situation.
3. Turning on DedeCms pseudo-static support cannot be completely configured in the background. There are many places that still need to be modified manually. The following explains the implementation method of DedeCms full-site pseudo-static, which is applicable to V5.3 and above. This time the DedeCms pseudo-static test environment is Windows IIS6. The principle of pseudo-static implementation for Linux or other servers is the same, as long as the idea is clear.
1) Pseudo-static home page of DedeCms:
Delete index.html in the root directory of the site and do not update the home page HTML in the future. Of course, you can also choose not to use a dynamic home page.
2) DedeCms channel | list page | article page pseudo-static:
Mainly achieved by modifying the two functions GetFileName() and GetTypeUrl(). For DedeCms V5.3, DedeCms V5.5 and DedeCms V5.6 versions, open /include/channelunit.func.php for modification. Note: DedeCms V5.7, the path of this file has changed, you can open /include/helpers/channelunit.helper.php.
A. Change the following code in GetTypeUrl():
//动态 $reurl = $GLOBALS['cfg_phpurl']."/list.php?tid=".$typeid; 替换为 //动态 $reurl = "/category/list-".$typeid.".html";
B. Change the following code in GetFileName():
//动态文章 if($cfg_rewrite == 'Y') { return $GLOBALS["cfg_plus_dir"]."/view-".$aid.'-1.html'; } 替换为 //动态文章 if($cfg_rewrite == 'Y') { return "/archives/view-".$aid.'-1.html'; }
3) DedeCms list paging pseudo-static:
Open /include/arc.listview.class.php and find the end of the GetPageListDM() function to get the dynamic paging list:
Replace
$plist = str_replace('.php?tid=', '-', $plist);
with
$plist = str_replace('plus', 'category', $plist);//将默认的plus替换成category $plist = str_replace('.php?tid=', '-', $plist);
Change the default link format of list paging /plus/list-1-2-1.html to /category/list-1-2-1.html. This step does not need to be changed.
4) DedeCms article paging pseudo-static:
Open /include/arc.archives.class.php and find the end piece of the GetPagebreakDM() function to get the dynamic paging list:
$PageList = str_replace(".php?aid=","-",$PageList);
is replaced with
$plist = str_replace('plus', 'archives', $plist);//将默认的plus替换成archives $PageList = str_replace(".php?aid=","-",$PageList);
5) DedeCmsTAG tag pseudo-static:
DedeCms默认的TAG标签URL,形如/tags.php?/dedecms5.7/,特别的难看。打开/include/taglib/tag.lib.php,找到lib_tag()函数下的:
$row['link'] = $cfg_cmsurl."/tags.php?/".urlencode($row['keyword'])."/";
替换为
$row['link'] = $cfg_cmsurl."/tags/".urlencode($row['keyword'])."/";
到这里,TAG标签URL中的“.php?”号就去掉了。
6)DedeCms搜索伪静态:
DedeCms搜索URL静态化比较麻烦,附带参数多不说,参数也可能变化,像搜索结果分页的URL就特麻烦,伪静态规则匹配复杂。将搜索URL中“search.php?…”直接替换为“search.html?…”,至于“?”号之后的参数以任意字符进行匹配。
依次打开include文件夹下的channelunit.func.php、arc.searchview.class.php、arc.taglist.class.php以及/include/taglib/hotwords.lib.php,查找“search.php?”替换为“search.html?”即可。
7)DedeCms问答伪静态:
问答模块的伪静态实现比较简单,只要后台开启伪静态支持即可,至于个别页面,如ask目录下的browser.php、question.php以及include目录下的common.inc.php、functions.inc.php都需要简单修改才可以匹配伪静态规则。注意一点,DedeCms V5.7问答模块整体升级了,之前的规则已经不适用了。
4、DedeCms伪静态规则:
依照上面的步骤修改完毕,接下来配置好httpd.ini文件和.htaccess文件伪静态规则,则DedeCms全站伪静态就完美实现。
1)IIS伪静态
打开httpd.ini文件,加入如下规则:
#首页伪静态规则,如果不使用动态首页,请勿必删除这一行,否则打开首页会出现死循环 RewriteRule ^(.*)/index\.html $1/index\.php [I] #列表页伪静态规则 RewriteRule ^(.*)/category/list-([0-9]+)\.html $1/plus/list\.php\?tid=$2 [I] RewriteRule ^(.*)/category/list-([0-9]+)-([0-9]+)-([0-9]+)\.html $1/plus/list\.php\?tid=$2&TotalResult=$3&PageNo=$4 [I] #文章页伪静态规则 RewriteRule ^(.*)/archives/view-([0-9]+)-([0-9]+)\.html $1/plus/view\.php\?arcID=$2&pageno=$3 [I] #搜索伪静态规则 RewriteRule ^(.*)/search\.html(?:(\?.*))* $1/search\.php?$2 [I] #TAG标签伪静态规则 RewriteRule ^(.*)/tags\.html $1/tags\.php [I] RewriteRule ^(.*)/tags/(.*)(?:(\?.*))* $1/tags\.php\?\/$2 [I] RewriteRule ^(.*)/tags/(.*)\/(?:(\?.*))* $1/tags\.php\?\/$2\/ [I] RewriteRule ^(.*)/tags/(.*)\/([0-9])(?:(\?.*))* $1/tags\.php\?\/$2\/$3 [I] RewriteRule ^(.*)/tags/(.*)\/([0-9])\/(?:(\?.*))* $1/tags\.php\?\/$2\/$3\/ [I] #问答伪静态规则,适用于DedeCmsV5.3-5.6版本,需要修改几处程序 RewriteRule ^(.*)/post\.html $1/post\.php [I] RewriteRule ^(.*)/type\.html $1/type\.php [I] RewriteRule ^(.*)/question-([0-9]+)\.html $1/question\.php\?id=$2 [I] RewriteRule ^(.*)/browser-1-([0-9]+)\.html $1/browser\.php\?tid=$2 [I] RewriteRule ^(.*)/browser-2-([0-9]+)\.html $1/browser\.php\?tid2=$2 [I] RewriteRule ^(.*)/browser-1-([0-9]+)-([0-9]+)\.html $1/browser\.php\?tid=$2&page=$3 [I] RewriteRule ^(.*)/browser-2-([0-9]+)-([0-9]+)\.html $1/browser\.php\?tid2=$2&page=$3 [I] RewriteRule ^(.*)/browser-([0-9]+)\.html $1/browser\.php\?lm=$2 [I] RewriteRule ^(.*)/browser-1-([0-9]+)-([0-9]+)\.html $1/browser\.php\?tid=$2&lm=$3 [I] RewriteRule ^(.*)/browser-2-([0-9]+)-([0-9]+)\.html $1/browser\.php\?tid2=$2&lm=$3 [I]
2)Apache伪静态:
打开.htaccess文件,加入如下规则:
#提供部分规则作参考 RewriteRule ^category/list-([0-9]+)\.html$ /plus/list.php?tid=$1 RewriteRule ^category/list-([0-9]+)-([0-9]+)-([0-9]+)\.html$ /plus/list.php?tid=$1&totalresult=$2&PageNo=$3 RewriteRule ^archives/view-([0-9]+)-([0-9]+)\.html$ /plus/view.php?aid=$1&pageno=$2 RewriteRule ^index.html$ index.php
更多DedeCMS相关技术文章,请访问DedeCMS教程栏目进行学习!
The above is the detailed content of How dedecms implements pseudo-static throughout the site. For more information, please follow other related articles on the PHP Chinese website!