Apache 301 redirect all but one file

.htaccess301-redirectapache-2.2redirect

I'm currently going back into an old domain and creating redirects for SEO purposes. I haven't done this much so I'm learning as I go along.

I'm trying to:

  • have some pages 301 directly to equivalent pages on the new site (done)
  • have one single page not redirect at all (need help)
  • have all other pages redirect to the new homepage (done)

So far I have:

RedirectMatch 301 contactinfo.html http://www.newdomain.com/contact.php
RedirectMatch 301 (.).html http://www.newdomain.com/index.php 

How can I disallow the redirection of a single page?

Best Answer

The Redirect directives don't really have the flexibility to do this. Try using mod_rewrite:

RewriteEngine on
# Equivalent to your first RedirectMatch
RewriteRule ^contactinfo\.html$ http://www.newdomain.com/contact.php [R=301,L]
# Avoids taking any action on this page.
RewriteRule ^filetonotredirect\.html$ - [L]
# Equivalent to your second RedirectMatch
RewriteRule ^.*\.html$ http://www.newdomain.com/index.php [R=301,L]