Forum Moderators: phranque

Message Too Old, No Replies

Newbie 301 redirect question

Trying to redirect multiple pages to one domain, with an exception

         

kmaines

4:32 pm on Jun 2, 2010 (gmt 0)

10+ Year Member



Hi,

I'm trying to redirect an old site to their new domain. I'm not worried about seo as the content has changed a lot, so I'd like to have all the pages just redirect to the homepage. There is also an exception to the redirect that the /documents directory shouldn't be redirected.

Anyway, I found started with the following (from this forum):

RewriteEngine on
RewriteCond $1 !^documents
RewriteRule (.*) [newdomain.com$1...] [R=301,L]

It works great, but it looks like it's redirecting subpages to the same subpage on the new server instead of the homepage. I know it's something obvious but I don't see it.

Two questions:

1. What is the $1 doing in the RewriteCond and the RewriteRule?
2. Should the (.*) be replaced by ^?

Thanks everyone!

g1smd

9:49 pm on Jun 2, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The $1 "backreference" is what copies over the path from pattern matching the request to the target filepath.

Omit the $1 from the target and just state example.com/ to redirect to the root.

You'll need the (.*) as you use the $1 it generates to make the compare in the RewriteCond.

If you also need to clear any attached parameters in the redirect, end the target example.com/ with an additional question mark right after the slash.

kmaines

2:55 pm on Jun 3, 2010 (gmt 0)

10+ Year Member



g1smd,

Thanks so much! It works perfectly. I'm just starting to learn about the power of redirects. Amazing.