加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > CMS系统 > wordpress > 正文

WordPress给页面URL添加.html后缀的方法

发布时间:2020-12-14 14:14:19 所属栏目:wordpress 来源:网络整理
导读:在WordPress中,尽管你把固定链接设置成 /%postname%.html 这种形式,也只能给文章的URL添加 .html 后缀,其余页面的URL都是没有 .html 后缀的。上次我们介绍了 如何给标签页添加.html后缀 ,这次我们讲讲如何给WordPress博客的 页面 URL添加.html后缀。 使

在WordPress中,尽管你把固定链接设置成 /%postname%.html 这种形式,也只能给文章的URL添加 .html 后缀,其余页面的URL都是没有 .html 后缀的。上次我们介绍了如何给标签页添加.html后缀,这次我们讲讲如何给WordPress博客的页面URL添加.html后缀。

使用插件

如果想给页面URL添加 .html 后缀,可以使用使用这款插件:.html on PAGES

如果想给页面URL添加 .php 后缀,可以使用使用这款插件:.php on PAGES

露兜亲测,两款插件均可以在WordPress 3.5下正常工作。

特定页面不添加后缀

.html on PAGES 插件会给所有页面都添加上.html后缀,但是问题又来了,如果我们不想给 sitemap 页面URL添加 .html 后缀,保持 /sitemap,而不是 /sitemap.html,那么怎么办呢?如果你有这个需求,可以用文本编辑器打开插件目录下的html-on-pages.php,查找:

add_filter('user_trailingslashit','no_page_slash',66,2);

将其替换成:

add_filter('page_link','blog_permalinks_page_link',10,2);
function blog_permalinks_page_link($permalink,$page) {
$pos = strpos($permalink,"/sitemap.html");
if ($pos !== false) {
$permalink = str_replace("/sitemap.html","/sitemap",$permalink);
}
return $permalink;
}

add_filter('user_trailingslashit',2);

接着查找:

function html_page_permalink() {

将其替换成:

function html_page_permalink() {
$string = $_SERVER['REQUEST_URI'];
$pos = strpos($string,"/sitemap.html");
if ($pos !== false) {
switch_to_blog(1); //We are using WPMU if you are not you won't need this line.
wp_redirect(get_option('home') . str_replace('/sitemap.html','/sitemap',$string),301);
exit();
}
else {
$pos = strpos($string,"/sitemap");
if ($pos !== false) {
$_SERVER['REQUEST_URI'] = str_replace("/sitemap","/sitemap.html",$string);
global $wp;
$wp->parse_request();
}
}

好了,修改就到此结束。你可以根据把代码中的 sitemap 改成你的页面别名.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读