WordPress URL 自动更正

标签 wordpress url

我犯了一个拼写错误,并尝试加载一个不存在的页面(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/

相关文章:

php - 使用 esc_js() 保存的输出数据

ruby-on-rails - Rails当前网址帮助器

iphone - 在 JSON 中发布用户名和密码

javascript - 网站更改正在缓存,不会为客户更新

mysql - Woocommerce mySQL 查询 - 列出所有订单、用户和购买的商品

mysql - Wordpress 限制查询结果

c# - 如何从 URL 调用中捕获参数

angular - 如何在 Angular 5 中删除 url 中的#?

asp.net 获取路径页面文件夹 url

php - 在未初始化的变量上使用 .= 运算符有多安全?