wordpress如何去掉html后面的反斜杠

wordpress通过以下代码实现了,tag,分类url后面添加反斜杠的效果

function nice_trailingslashit($string, $type_of_url) {
    if ( $type_of_url != 'single' )
      $string = trailingslashit($string);
    return $string;
}
add_filter('user_trailingslashit', 'nice_trailingslashit', 10, 2);

现在我重新创建了一个自定义分类页面经验,原来的是优惠,

但是这个新建的自定义分类,发布的文章后url形式上这样的。

http://www.xxx.com/jingyan/123.html/

html结尾会多一个反斜杠/
这个有什么办法可以去除吗?

阅读 4.5k
3 个回答

可以把trailingslashit函数代码贴出来.

去除字符串末尾 ‘/’ 可以用 rtrim

➜  ~ cat test.php
<?php
    echo rtrim('http://www.xxx.com/jingyan/123.html/', '/');
➜  ~ php test.php
http://www.xxx.com/jingyan/123.html

用法参考:rtrim

新手上路,请多包涵

可一个改htaccess

RewriteCond%{REQUEST_FILENAME}!-d
RewriteRule^(.*)/$ /$1 [L,R=301]
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题