How to Redirect all pages in a directory to a single URL

I just discovered this neat little trick. I had to close down a subdomain as the CMS I was using was no longer being supported, and I could not afford a coder to fix my problems. So I places this in the .htaccess file in the root of the old subdomain:

RewriteEngine on
RewriteRule ^(.*)$ http://www.webologist.co.uk/ [L,R=301]

Previously I was attempted to use the standard Redicect 301, but this did not work, as the file URL’s were redirected, causing 404 page not found errors. This code sorts it all out.

  1 comment for “How to Redirect all pages in a directory to a single URL

  1. Josh Katinger
    November 23, 2008 at 8:11 pm

    Good info….properly redirecting is key to preserving SEO. FYI…we just built http://www.errorlytics.com for exactly this reason. Would love your feedback on it. It basically allows you to analyze your 404s and write redirects in a fast an “plain English” way without having to write regex.

Leave a Reply

Your email address will not be published. Required fields are marked *