How to create a site redirect on a sub-directory using .htaccess and PHP
I needed to make the old http://socialsynergyweb.org/oardc domain point to the new home at http://localfoodsystems.org (and include all sub-directory listings under /oardc). Plus, it was desired to place a message letting people know about a timed redirect, and to "update your book marks".
So, here is what I did:
The .htaccess file:
RedirectMatch 301 ^/oardc/.*$ http://socialsynergyweb.org/lfs/index.php
This simply finds everything that is under http://socialsynergyweb.org/oardc and redirects to http://socialsynergyweb.org/lfs/index.php
When you reach http://socialsynergyweb.org/lfs/index.php the code in index.php looks like this:
<?php $message =<<<HTML <h3><p>This site has moved! Please update your bookmarks. You will be redirected to <a href="http://localfoodsystems.org">Local Food Systems</a> in 5 seconds.</h3></p><br /><h3><p> If you are not redirected, please <a href="http://localfoodsystems.org">Click here.</a></h3> HTML; ?> <?php header("Refresh: 5; URL=http://localfoodsystems.org"); echo $message; //this is the message exit(); ?>
That's it. The above code redirects to http://localfoodsystems.org after a 5 second delay, and prints the message shown in the heredoc section above.
- Sam Rose's blog
- Login to post comments

