I have a WordPress installation and a few months ago I decided to change the theme. The new theme required to change the total posts per page from 8 that was in the first theme to 10 in the next theme, so the new theme as expected does not have all of the pages that previews theme had.
The problem is that now Google looking for page /archives/tag/tag-name/page/5 while that page does not exists.
What I need to do is to make a rewrite rule, for the case that the page does not exists to redirect with 307 (Temporary moved on) on the root tag or category page in a URL that will looks like that /archives/tag/tag-name/
In my htaccess I have try that :
RewriteEngine On
RewriteBase /
# Check if any tag has a page that not exists
# and redirect to first page of this category
RewriteCond ^archives/tag/.*/page/[0-9]+(/?)$ !-f
RewriteRule ^archives/tag/(.*)/page/[0-9]+(/?)$ http://www.my-site.ext/archives/tag/$1/ [L,R=307]
# Check if any category has a page that not exists
# and redirect to first page of this category
RewriteCond ^archives/category/.*/page/[0-9]+(/?)$ !-f
RewriteRule ^archives/category/(.*)/page/[0-9]+(/?)$ http://www.my-site.ext/archives/category/$1/ [L,R=307]
# Default wordpress rewrite rules
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
But the above rules redirect the existing pages too, in the first page
Any help please ? 🙂
I think what you’d need to do is handle this at the WordPress level, not Apache.
In your theme’s functions.php file, try hooking the “template_redirect” action, something like this:
You’ll have to figure out the right logic for
[other conditions]and$some_better_urlyourself.(This general idea is based on the
wp_old_slug_redirectfunction, which is found in WordPress’s query.php script)