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
Category: Web

?cat=-1 Indexed Versions Of Homepage

I'm finding some strange query strings on my homepage are indexed in Google and causing duplicate content. A couple of examples: https://sciencetrends.com/page/103/?cat=-1 https://sciencetrends.com/?cat=-3 I'm not sure how or why these pages are being created in Wordpress but it seems common for even large Wordpress sites: https://techcrunch.com/page/10/?cat=-1 https://blogs.wsj.com/law/page/10/?cat=-1 https://www.nytco.com/page/10/?cat=-1 http://www.bbcamerica.com/page/10/?cat=-1 Ideally, I'd like to remove all ?cat=* pages from the site and have then resolve to 404. Any thoughts on the best method to do so, .htaccess, Wordpress modification, etc.?
Category: Web

How to use the Yoast SEO wpseo_canonical filter to set a canonical URL for /, /au/ & /uk/ sites in a MU environment

Our company has markets in USA, UK & Australia. We've just started using WP MU on our development server where the USA/global version is @ www.example.com, and then there are www.example.com/uk/ & www.example.com/au/. We're probably going to create an AJAX function to redirect the visitor based on their geographical location to the appropriate website, with www.example.com being the catch-all. I've come across the Yoast SEO wpseo_canonical filter which might help us set a canonical URL for all of our posts …
Category: Web

Wrong canonical link on wp-admin pages

I have a subdomain: https://blog.example.com/ I forcibly redirects to directory: https://www.example.com/blog By changing site URL and some RewriteRule on .htaccess. My .htaccess: <IfModule mod_rewrite.c> RewriteEngine On RewriteBase /blog/ RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /blog/index.php [L] RewriteCond %{HTTP:X-Forwarded-Host}i ^example\.com RewriteCond %{HTTP_HOST} ^blog\.example\.com$ RewriteRule ^/?(.*)$ https://www.example.com/blog/$1 [L,R=301,NC] RewriteCond %{HTTP:X-Forwarded-Proto} !https RewriteCond %{HTTPS} off RewriteRule ^/?(.*)$ https://www.example.com/blog/$1 [L,R=301,NC] </IfModule> My wordpress address and site address are: WordPress Address (URL): /blog Site Address (URL): https://www.example.com/blog Now the …
Category: Web

How to change custom paginated URLs using PHP code

See our website has pagination URls like below https://www.xxxxxxxx.com/xxxxxxxx/yyyy/zzz/?xx_xxx_page=2 https://www.xxxxxxxx.com/xxxxxxxx/yyyy/zzz/?xx_xxx_page=3 https://www.xxxxxxxx.com/xxxxxxxx/yyyy/zzz/?xx_xxx_page=4 ISSUE: These pagination URLs are not indexing by Google. (As it has showing same canonical URL for all these pagination URLS , it showing error as Duplicate URL) Proposed solution: we want to create all these pagination pages separately with Specific permalink(URL). Without changing URL Structure and without disturbing Pagination https://www.xxxxxxxx.com/xxxxxx/yyyy/zzz-2/ https://www.xxxxxxxx.com/xxxxxx/yyyy/zzz-3/ Any one please help me with fasible solutions. Thank you
Category: Web

How to fix Ahref error showing wordpress admin pages as "Duplicate pages without canonical"?

I am using Ahref tool for performing a site audit on a WordPress based site. The site audit shows an error "Duplicate pages without canonicals" with a page count of 110. When I check the details all the duplicate pages are wordpress admin pages. For example "https://www.example.com/login.php", "https://www.example.com/login.php?redirect_to=https://www.example.com/some-blog-post". I can not find a way to solve this issue. Solutions tried so far: 1 - Tried blocking wp-admin and wp-login pages through robots.txt (didn't work) 2 - Tried using plugin "wp-hide …
Category: Web

Customize rel=canonical tag for single blog post

I wrote a guest blog post for another website. I'd like to publish this same blog post on my website but include a canonical URL that points to the original publisher. This allows me to post the article on my website while notifying Search Engines of the canonical location of the post and avoiding SEO penalties. In the wp_head action, WordPress prints a rel=canonical tag automatically and places it in the head for posts. I tried to use a snippet …
Category: Web

Setting custom canonical urls

I have a page that requests and displays information from a database. All is fine but I'm having some trouble setting custom canonical URLs for this single page only and its URLs (with parameters inside). Example: https://example.com/primary-page https://example.com/primary-page?requested_id=1 https://example.com/primary-page?requested_id=2 https://example.com/primary-page?requested_id=3 and so on... These links with "?requested_id=id" automatically inherit the same canonical link as the "primary-page". Which I would like to modify in order for these links to have their own and full URLs as canonical link. I've been looking …
Category: Web

How to prevent automatic redirection of 404 errors and "incorrect" URLs?

Wordpress has a feature whereby it will automatically redirect your URLs if it percieves them to be written wrongly. Here is an example: I have a page called my-page If I go to: www.mysite.com/something/my-page/ it will immediately redirect me to www.mysite.com/my-page/ as nothing exists at the first URL. How can I turn this feature off, and instead just get a 404 if incorrect URL's are typed in?
Category: Web

Change cannonical URL after changing url with add_rewrite_rule()

So, I'm making a plugin for some niche application for my customer which involves a table with data, and I created a page within the plugin to show more in-depth information about the table row. This is how I'm making the rewrite: function mytableplugin_page_rewrite(){ $page_slug = 'mytablepluginpage'; // urls will be in the form // /your-page/42/ add_rewrite_rule( 'mytableplugin/([0-9a-zA-Z_-]+)/?$', 'index.php?pagename=' . $page_slug . '&tid=$matches[1]', 'top' ); } But the redirect doesn't affect the canonical URL, so every "mytableplugin" page has the …
Category: Web

Blog home page has canonical link that is incorrect. Do not see where to change this

As part of our website we have a wordpress blog in a subdirectory. I scanned our main site for broken links. The scan included the wordpress blog in the subdirectory. Some "broken links" showed up that have never been present before. The problem is that the "otherblog" has nothing whatsoever to do with our website--it is a separate property. We don't know how the value for the "otherblog" is getting in. The html looks like this: <link rel="canonical" href="https://www.otherblog.com/blog/"> <link …
Category: Web

Wrong Canonical url link

I have a weird problem. I have a page that changed URL (because it's parent changed name). Example Link https:www.mysite.com/my-services/service-1 is now: https:www.mysite.com/services/service-1 the canonical url however is still the original one: https:www.mysite.com/my-services/service-1 which is wrong. (it should be the new link) This is what I tried: I had the redirection plugin to handle the redirect, but have switched that one iff > does not solve the problem I have switched of Yoast > doesn't help I switched on Yoast …
Category: Web

remove rel=next on home page but not others

There is a major problem with most new templates for WordPress that want you to set your homepage to Your Latest Posts. This is to enable many of the great theme features to work. The problem with this is that the front page (even though not a blog page) is seen as a paged entity by the wordpress core and yoast seo too. So what does this mean? You have a homepage www.mysite.com if you visit your page and look …
Category: Web

Remove WP Core canonical for category pagination

It seems that WP is adding a canonical to the root of my pagination, and no indexing all other pages on Category pages. For example, /locations/residential/?_page=2 is no-index, and gives /locations/residential/ as canonical. I have tried this to attempt to remove this for these Category pages, but Screaming Frog still says the pagination is no-index and rel=canonical to the root page. add_filter( 'redirect_canonical','custom_disable_redirect_canonical' ); function custom_disable_redirect_canonical( $redirect_url ){ if ( is_category() ) $redirect_url = false; return $redirect_url; } Any idea …
Category: Web

add the post as canonical for attachment page wordpress

the attachment page should have canonical added to the main post on attachment page (image.php) I currently have (automatically added by All in One Seo Pack): <link rel="canonical" href="https://example.com/main-post/image-name" /> And I want to change it to point to the post (where this image is attached) <link rel="canonical" href="https://example.com/main-post" /> You can ignore All in One Seo Pack if that is difficutl to change, and maybe simple provide a way to add the canonical to the main post.
Category: Web

Wordpress Redirecting Non Category Pages /page/nnn to their Canonical URLs

I seemingly to have a strange issue I have found in almost every other Wordpress site. Suppose, you have set your Blog home to a static WP page /myhome. And you have a separate page for blog /blog. Now, this works fine and should be: /blog /blog/page/2 /blog/page/3 /blog/page/4 But, for all other pages, e.g. /about-us, these links also work: /about-us/page/2 /about-us/page/3 /about-us/page/4 And show the content of the /about-us page. My problem is that /about-us/page/2 should ideally redirect to …
Category: Web

How to use relative urls without canonical and prev-next?

I want to use relative urls instead of absolute urls but not all types. Here's just a few examples. Exclude: canonical urls, prev and next post like this: <link rel="canonical" href="https://www.example.com/title/" /> <link rel='prev' title='title 2' href='https://www.example.com/title-2/' /> <link rel='next' title='title 3' href='https://www.example.com/title-3/' /> Include: All categories, menu, posts, pages, js, css, wp-content/uploads, etc. That's what I need.
Category: Web

Wordpress replaces "https://" with "//" for Site & Wordpress-URL

When I save "https://example.com" in General Settings as my Site & Wordpress URL, it gets replaced by "//example.com". To analyze the problem, I checked the Wordpress database, but 'WP_HOME' and "WP_SITEURL" are correctly stored as "https://example.com". Actually, this is not a big problem, but Yoast SEO also shows my canonical URL as "//example.com". So I need to fix that problem ...
Category: Web

adding wordpress yoast SEO canonical url from "transition_post_status" hook

I am using transition_post_status hook to add get some data at the time of post is publish but i can access any variables but when i am trying to set canonical url from add_filter it is return 500 error // Add the hook action add_action('transition_post_status', 'send_new_post', 10, 3); // Listen for publishing of a new post function send_new_post($new_status, $old_status, $post) { if('publish' === $new_status && $post->post_type === 'post') { print_r('this is done'); $post_meta = get_post_meta($post->ID, '', true); $object_id = $post_meta['mydo_post_id'][0]; …
Category: Web

tried putting this <link rel="canonical" href="https://www.example.com<?php echo $_SERVER['REQUEST_URI'];?>"> as canonical tag

This message pop up at dashboard "Your website URL has recently been changed. Automatic payments and customer emails have been disabled to prevent live transactions originating from development or staging servers." As i am new in this field so i don't have any idea what should i do to solve this.
Category: Web

About

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