WP didn't redirect to canonical category URL

I have a problem with canonical redirect.

mydomain.com/mycat is the correct category URL but the following URL works too: - mydomain.com/asdfa/mycat - mydomain.com/1234/mycat - mydomain.com/anythingyouwant/mycat

And all these URLs show the category mycat... The canonical is mydomain.com/mycat and now Google give results with bad URLs.

Can you please help me because I didn't understand why.

I have the same template on other website and when we try to go to mydomain.com/asdfa/mycat, WP redirect to the canonical URL mydomain.com/mycat

Topic rel-canonical wp-redirect categories redirect themes Wordpress

Category Web


Maybe this answer about canonical urls can help you. It won't tell you how to do the redirects, but it will solve the Google search engine problem.


Check error logs - probably PHP sent some content to browser before WordPress tried redirection (and failed because headers was already sent).

Check if you don't have any ?> on the end of config, theme and plugins files, and ofc check if deactivating plugins and temporary changing theme to one of Twentys help, it could help you target problematic part.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.