-
rob33
It may have done way back.
How to rectify.
Is there a way to tell google not to bother with these pages.
I went through yoast set up and prevented what i could from being indexed bar posts and pages and now there are like 89 redirects :/
-
Alvind
For now, you can try using this PHP code to set a permanent redirect to the homepage when the slug matches the ‘/page/5’ pattern:
add_action('template_redirect', function() { // Check if the current request matches the pattern '/page/*' if (preg_match('/\/page\/[\w\d]+/', $_SERVER['REQUEST_URI'])) { // Redirect to the homepage with a 301 permanent redirect header wp_redirect(home_url(), 301); exit(); } });
This will inform Google that this URL has been moved to another URL and should not be indexed. You can also submit the latest sitemap to the search console as well.
-
rob33
Thanks.
And there are a number of homepage/page5 redirects – page 11, etc will this address those too?
There are also other pages with redirects, I’m guessing I can do the same with this code?
One thing that might be happening is when I publish a post, the original slug is sometimes overwritten by the title, so after publishing I amend the slug, but maybe google is grabbing the original published slug.
-
Alvind
And there are a number of homepage/page5 redirects – page 11, etc will this address those too?
Yes, it will apply to any slug that has /page/* followed by any character or number after that. As for other redirects, it depends on where the redirection goes. If it goes to the homepage, you can use the same code with a slight modification to check the slug pattern.
..when I publish a post, the original slug is sometimes overwritten by the title..
I think this is the default behavior, as the slug will always be made up from the title when the permalink structure is set to post name or a custom structure.
-
rob33
Hello – twice my replies to you have been deleted – pls advise whats happening.
I replied talking about what Namecheap had stated etc
-
Alvind
Sorry about that. When did you send those replies? I didn’t see any reply notifications on this topic coming through our system. Could you resend them?
-
rob33
No matter,
I found that some redirects are coming from wp showposts plugin as:
https://menspleasures.com/diy/page/2/ redirects to homepage
-
Alvind
Try replacing the code I provided here:
https://generate.support/topic/unable-to-locate-strange-redirects/page/2/#post-107703To this one:
add_action('template_redirect', function() { // Get the current URL path $current_url_path = trim(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH), '/'); // Check if the URL path matches the pattern 'page/*' and that it's at the root level if (!is_admin() && preg_match('/^page\/[\w\d]+$/', $current_url_path)) { wp_redirect(home_url('/'), 301); exit(); } });
- You must be logged in to reply to this topic.