I have a WordPress site and I made a folder inside the WordPress installation folder called en
. So suppose if my site URL is example.com
which loads my WordPress site, the visitor should can access the contents of en
folder by visiting example.com/en/
URL.
But unfortunately the WordPress redirects the visitor to a page with URL like example.com/environmental-advertising/
, which is a blog post. As I understood, WordPress's redirect_canonical
causing this redirect.
So how can I prevent this type of redirects for a certain URLs like example.com/en/
?
*UPD #1: The en
folder is another WordPress installation.
You can use redirect_canonical
to tell the function to not use this url when try to find the page. Here is the code:
add_filter( 'redirect_canonical', 'custom_redirect_canonical', 10, 2 );
function custom_redirect_canonical( $redirect_url, $requested_url ) {
if( $requested_url == 'http://example.com/en' ) {
return $requested_url;
}
return $redirect_url;
}
Please note the following:
redirect_canonical
will skip.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With