I’m attempting to create “pretty” URLs for a page which takes query var input to display content. The page is called “details” and has a php script which takes the query_var idCourse and calls up specific information from the database. The reason I want to use the pretty is link is so that it can be unique for Facebook, Twitter, etc — and the various plugins I have which seem to use the canonical link from core.
I have a rewrite that works. This is the WordPress page, with the query var request (what I call the base request):
This is the pretty request of the same page:
This is the rewrite:
add_rewrite_rule('^details/([^/]+)/?$', 'index.php?pagename=details&idCourse=$matches', 'top');
As per posts here, I added a rewrite tag:
If you request the pretty URL, it successfully calls up the correct information. However, the canonical link on the page is the base request and not the pretty URL. Is it possible to have the canonical link (which the social sharing plugin uses) be the pretty request?
This seems to be possible based upon my other pages. I mean if you have permalinks set up, it’ll show category/postname/etc. Why can’t I do this?
Read more here: Rewrite rules and the canonical link