I moved a wordpress site to another domain. I want to preserve the google links however and help it re-index the new site. 

I did a 301 redirect but it only works for the root director. When someone goes to `http://oldsite.com/directory/post-name-here/` I want them to be forwarded to `http://newsite.com/directory2/post-name-here/`. Both websites are in subdirectories. Is there a way to do it with in PHP? Or would I need a mod-rewrite? 

---

What finally worked for me was this:

My oldsite file structure is like so:

```
/public_html/
     index.php
     /development/
         .htaccess

```

To recap, I wanted to forward everything coming into the development directory to the new website. This is the code of the .htaccess in the `development` directory. 

```
<IfModule mod_rewrite.c>

RewriteEngine On
RewriteCond %{HTTP_HOST} ^oldsite.org$ [OR]
RewriteCond %{HTTP_HOST} ^www.oldsite.org$
RewriteRule (.*)$ http://newsite.com/newdirectory/$1   [R=301,L]

```

Thank you so much to Peter