301 from example.com/blog to example2.com/blog

Random stuff about serendipity. Discussion, Questions, Paraphernalia.
Post Reply
randyr505
Posts: 2
Joined: Wed Mar 19, 2008 6:56 pm

301 from example.com/blog to example2.com/blog

Post by randyr505 »

I am trying to get 301 redirect to work so that my old links in google at example.com/blog/... are 301'd to example2.com/blog/...

I have a .htaccess in my root directory and ofcourse the one in the serendipity directory (/blog). Which should I edit?

I currently have the following in my example.com/.htaccess

rewritecond %{http_host} ^www.example.com [nc]
rewriterule ^(.*)$ http://www.example2.com/$1 [r=301,nc]
rewritecond %{http_host} ^example.com [nc]
rewriterule ^(.*)$ http://www.example2.com/$1 [r=301,nc]

These are hosted on the same site. I simply changed my domainname. Everything works fine except my blog (including other subdirs) so I know it is because of the /blog/.htaccess.

Any help would be greatly appreciated.

Thanks,

Randy
judebert
Regular
Posts: 2478
Joined: Sat Oct 15, 2005 6:57 am
Location: Orlando, FL
Contact:

Post by judebert »

Apache interprets the deepest .htaccess first. So it first tries to handle all the /blog/.htaccess rules, then the /.htaccess rules.

You'll want to add the redirect to your /blog/.htaccess and configure Serendipity to understand the new domain name.
Judebert
---
Website | Wishlist | PayPal
randyr505
Posts: 2
Joined: Wed Mar 19, 2008 6:56 pm

Post by randyr505 »

Thanks for the reply.

Yes, I understand that is how it works. I should have provided more information.

I have the following added to the default serendipity .htaccess file:
RewriteCond %{http_host} ^www.example.com [nc]
RewriteRule ^(.*)$ http://www.example2.com/blog/$1 [r=301,nc]

It works ok when I go to example.com/blog (301's to www.example2.com/blog) but it doesn't work for www.example.com or direct links to something like:
http://example.com/blog/archives/2008/03.html

The error is:

Bad Request
Your browser sent a request that this server could not understand.

Additionally, a 400 Bad Request error was encountered while trying to use an ErrorDocument to handle the request.

However, http://example.com/blog/archives/2008/ works just fine.

When I go to www.example.com it goes to
http://www.example2.com/blog//home/dire ... 2.com/blog

In other words I only have it partially working. I don't understand the mod_rewrite stuff enough to figure this out what will work without messing up what serendipity is doing.
judebert
Regular
Posts: 2478
Joined: Sat Oct 15, 2005 6:57 am
Location: Orlando, FL
Contact:

Post by judebert »

I think the problem is that we need to define this as the last rule to be run, or else restart the entire chain again. I'd try adding L or N to my flags (so they'd read [NC,L] or [NC,N] and see if that helped.
Judebert
---
Website | Wishlist | PayPal
Post Reply