我犯了一个拼写错误,并尝试加载一个不存在的页面(localhost/wordpress-sia/our-missio),但它仍然将我带到正确的页面(localhost/wordpress-sia/our-mission)。
我很好奇它如何自动更正 URL,但找不到任何内容。有人可以解释一下这是怎么回事吗?
最佳答案
WordPress 核心中执行此操作的函数是 redirect_canonical()
,默认情况下启用,但如果您选择可以将其关闭。
https://developer.wordpress.org/reference/functions/redirect_canonical/
Search engines consider www.somedomain.com and somedomain.com to be two different URLs when they both go to the same location. This SEO enhancement prevents penalty for duplicate content by redirecting all incoming links to one or the other.
Prevents redirection for feeds, trackbacks, searches, and admin URLs. Does not redirect on non-pretty-permalink-supporting IIS 7+, page/post previews, WP admin, Trackbacks, robots.txt, searches, or on POST requests.
Will also attempt to find the correct link when a user enters a URL that does not exist based on exact WordPress query. Will instead try to parse the URL or query in an attempt to figure the correct page to go to.
不建议您这样做,但以下是禁用方法。
创建此目录和文件(必须使用的插件):
/wp-content/mu-plugins/disable-redirect-canonical.php
<?php
add_action( 'init', function() {
remove_filter( 'template_redirect', 'redirect_canonical' );
} );
如果您愿意,此代码可以放入您主题的functions.php 文件中。
关于WordPress URL 自动更正,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47244112/