您不想 100% 删除它以在 WordPress 中进行 SEO。#
但是,如果您愿意,这将向您展示如何操作。 WordPress“/”修复。我的 WordPress Gist
可以转换,所以很有帮助
配置文件:nginx.conf
...
location /mirror/foo/ {
...
rewrite ^(.*[^/])$ $1/ permanent;
...
}
...
描述 WordPress "/" PHP 修复
如果博客设置为添加斜杠,则检索斜杠字符串。
如果永久链接结构有尾部斜杠,则有条件地添加尾部斜杠,如果没有,则去除尾部斜杠。字符串通过‘user_trailingslashit’ 过滤器。如果博客未设置为包含斜杠,将从字符串中删除尾随斜杠。
用法
<?php user_trailingslashit( $string, $type_of_string ); ?>
参数
$string
(string) (false) URL with or without a trailing slash.
Default: None
$type_of_url
(string) (false) The type of URL being considered (e.g. single, category, etc) for use in the filter.
Default: None
Return Value (string)
根据永久链接结构添加/删除尾部斜杠。
codex.wordpress。 /Function_Reference/user_trailingslashit
2。
如果要添加“/”
<?php trailingslashit( $string ) ?>
例子
<?php
$path = trailingslashit( '/home/julien/bin/dotfiles' );
?>
$path 现在将包含:
/home/julien/bin/dotfiles/
(注意尾部的斜杠)
https://codex.wordpress.org/Function_Reference/trailingslashit
3。
这是新的
任何测试中最重要的部分是断言。断言是您期望从系统获得的值与您实际获得的值之间的比较。最简单的测试可能只包含一个断言。示例:
public function test_trailingslashit_should_add_slash_when_none_is_present() {
$this->assertSame( 'foo/', trailingslashit( 'foo' ) );
}
assertSame() 方法接受两个参数:期望值(在本例中为硬编码字符串 'foo/'),以及实际值(trailingslashit()) 返回的值。
常见断言的注释列表可以在下面找到。
https://make.wordpress.org/core/handbook/testing/automated-testing/writing-phpunit-tests/#assertions
试试这些规则:(in www.example.com's server block) rewrite ^/$ http://example.com permanent break; rewrite ^/main(.*)$ http://example.com$1 permanent break; rewrite ^(.*)$ http://blog.example.com$1 permanent; 确保你重新加载 nginx。
使用此配置:
-
http://www.example.com/ *重定向到
-
http://example.comt -
-
http://example.com/something - 其他所有内容都重定向到