I'm focusing on a sizable project which involves taking 1000's (30,000+) static webpages and making it to some Content management systems.

The problem is a number of these pages are replicates inside their sites. I wish to keep your Search engine optimization intact by utilizing 301 redirects, however, I don't know how to pull off doing this type of large redirect (301).

Here's a good example of the present directory structure for that pages.





As you can tell page.html is copied in most the sites.

For that new Content management systems the Hyperlink to that page would certainly be /page.html.

Working example, visit: http://world wide web.jakeisonline.com/stackoverflow/3345518-mass-301-redirect/page.html

You ought to be rerouted right to /page.html

Options +FollowSymlinks
RewriteEngine on

RewriteRule ^(.*)page.html /page.html [R=301,NC]

This can always redirect http://world wide web.foo.com/something/something/something/page.html to http://world wide web.foo.com/page.html utilizing a 301 hard redirect.

The rewrite rule performs this by searching in the URL, identifying contrary before page.html is incorporated (excluding the domain itself) and when it's, will 301 redirect. To help you literally use any sub-level, so that as lengthy because it finishes with page.html, it'll redirect to /page.html within the root directory.

Just in case you are wondering what [R=301,NC] means,

 R // means simple redirect
 R=301 // means redirect with a 301 header
 NC // means no-case, or case insensitive
 L // can also be used to say 'ignore all the other rules after this'

Do this rule:

RewriteRule ^([^/]+/)+page\.html$ /page.html [L,R=301]

Or any arbitrary page.html:

RewriteRule ^([^/]+/)+([^/]+)\.html$ /$2.html [L,R=301]