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):

https://www.fxphd.com/details/?idCourse=465

This is the pretty request of the same page:

https://www.fxphd.com/details/465/

This is the rewrite:

add_rewrite_rule('^details/([^/]+)/?$', 'index.php?pagename=details&idCourse=$matches[1]', 'top');

As per posts here, I added a rewrite tag:

  add_rewrite_tag('%details%', '([^&]+)');

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?

Thanks.

Read more here: Rewrite rules and the canonical link


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: