redirect all subpages with 301 redirect to the start page with exceptions

Viewed 48

I bought a domain (PBN) that has a lot of subpages with a lot of backlinks. I want a 301 redirect so that all subpages that no longer exist (but contain many backlinks) can be redirected to the start page. With the exception of legal notice, data protection, etc. How can I redirect all sub-pages to the start page with a few exceptions? The website was set up on Wordpress.

I've tried this code, but it doesn't work, does anyone have any ideas? Thanks in advance

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_URI} !^/(index\.php|impressum)?$ [NC]
RewriteRule ^.*$ / [L,R=301]
</IfModule>
1 Answers

The website was set up on Wordpress.

Presumably, it still is?

You need to make sure you only redirect direct requests and not rewritten requests by the later rewrite to the WordPress front-controller, which will otherwise create a redirect-loop.

Try the following instead:

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule !^(index\.php|impressum)?$ / [NC,R=301,L]

I've moved the previous condition to the RewriteRule pattern.

You will need to clear the browser cache before testing and test with 302 (temporary) redirects to avoid potential caching issues.

Although it would probably be better for search engines and users if you create a custom 404 for these pages instead. A many-to-one redirect to the homepage is likely to be seen as a soft-404 by Google and users are left confused as to what happened to the old content.

Related