Stubborn mod_rewrite problem

wordpress

#1

I’ve moved a WordPress blog from oldsite.com/blog/ to newsite.com/ (the root directory). The blog itself transferred without a hitch, but I’m trying to write an .htaccess file to put at oldsite.com/blog that keeps all old links to the blog’s posts working. The idea is that http://oldsite.com/blog/anything redirects to http://newsite.com/anything. The current version, saved at http://oldsite.com/blog/.htaccess, reads this way in its entirety:

Options +FollowSymLinks RewriteEngine On RewriteBase /blog/ RewriteRule (.*) http://www.newsite.com/$1 [R=301,NC,L] And that works for everything except one address: http://oldsite.com/blog <-- without the trailing slash. That URL will redirect to this: http://newsite.com//home/username/oldsite.com/blog.

As far as I can tell, when the URI lacks a trailing slash, the RewriteBase doesn’t work right, and it somehow interprets $1 as the full filesystem path of the directory, even though I’m not telling mod_rewrite to do that anywhere. I think I understand the problem, but no matter what I try–and I’ve tried literally dozens of things, for hours–I can’t get it to work. Can someone please help me?


#2

Update: Among the many things I’ve tried, here is the most recent. I removed http://oldsite.com/blog/.htaccess and created http://oldsite.com/.htaccess, which consists only of this:

RedirectMatch 301 ^/blog(.*) http://newsite.com.com$1And that also works for everything except http://oldsite.com/blog sans trailing slash. Now, that one URL redirects to this: http://newsite.com/http://oldsite.com//home/username/oldsite.com/blog/.

This is so awesome! It appears that when the trailing slash is left off, mod_rewrite decides that (.*) is a hugely expanded combination of %{HTTP_HOST} and %{REQUEST_FILENAME}. Is this because we’re running PHP as a CGI? Are there environment variables I have to set? I’m very much at sea here. Thank you!