As a WordPress user, you should have heard about two closely related terms: pretty permalinks and canonical redirection. Pretty permalinks can help your URLs look nicer and more informative, while canonical redirection can help eliminate duplicate content, both can lead to better page ranking on search engines.
The problem is, when you want to create a virtual (fake) page, whose permalink ends in an extension, for example
http://example.com/my-fake-page.html, the canonical redirection will redirect your permalink to something like this:
This happens because you are using a permalink settings (in Settings → Permalinks) that ends in a trailing slash, i.e.
/. With canonical redirection turned on (which should never be turned off actually), any URL not ending in a slash will be appended with one.
The easiest way to solve this issue is to filter the
redirect_canonical hook and return false, but whether this approach works or not greatly depends on how you create your virtual page.
Nevertheless, if you add the fake page using the below snippet (or similar):
// Adding a new rewrite rule
$newrules = array();
$newrules['my-fake-page\.html$'] = 'index.php?fake_page=my-fake-page';
return $newrules + $rules;
// Tell WordPress to accept our 'fake_page' query variable
then to disable canonical redirection (for our fake page’s URL only), you can do something like this:
// Cancel the redirection for our fake page
$fake_page = get_query_var('fake_page');
Now if you re-visit the fake page, i.e.
http://example.com/my-fake-page.html, you will see no trailing slash at the end of the URL, or in other words, no canonical redirection has occurred!
Take Social Sharing to
the Next Level with Monarch!