[WordPress] About the URL autocompletion function in WordPress

There is an unimpressive URL autocompletion function in WordPress which a lot of the users or developers may not know.
This function can find the most similar URL even if the URL input is not exactly right.
For example: there is a permalink http://www.example.com/testpost
If you mistakenly input http://www.example.com/testp, the WordPress can still help you find the testpost. This sounds nice. But it can cause some problems. For example, I want to add a rewrite rule to make http://www.example.com/en point to http://www.example.com/?lang=en. This autocompletion function will still try to find something similar to 'en' instead of giving me the page of http://www.example.com directly. So we have to turn off this function.
Here is the solution:
add_action( 'redirect_canonical', '__return_false');
After adding this action, this autocompletion function will be turned off and the rewrite rules will successfully work.

评论

此博客中的热门博文

Openwrt路由器上配置shadowsocks透明代理+gfwlist(PAC)

Configure shadowsocks transparent proxy + gfwlist(PAC) on OpenWRT Router

Using Haproxy + shadowsocks (ha + ss) to setup multi ss backend and load balance