WordPress: Redirect Blog to First Post

I just created a simple WordPress installation. It was only going to be short pages and a simple shopping cart, but at the last minute, they decided to add a blog. Since the area for text was so small, we decided to only have one post for every page. As it would only act as duplicate content, there is no point in using the blog home page at all.

With some help from WP Recipes, I created this code to redirect the blog home template (home.php) to the first post:

home.php (Blog Home Page):
Redirect To First Post
if (have_posts()) {
while (have_posts()) {

It’s actually very simple. It just uses the WordPress Redirect function to redirect to the first permalink that would show up on that page.

Ashton Sanders

(P.S. If you haven’t heard, Adobe just released the pre-order for CS5… If I were to get one of the packages today, I’d probably get: Adobe Web Premium CS5. It looks ridiculously epic.)

.htaccess 301 Redirect: Moved Permanently

I’ve already discussed how to create a 301 permanent redirect using PHP that allows you to forward one page to another. But what if you you have an entire site to redirect? What if you’ve changed domain names? There has got to be a better way to redirect your site besides, adding a php 301 redirect to every page. Well there is! It’s called .htaccess.

My next post will be a quick introduction to “.htaccess”.

If you only want to redirect from one page on your site to another, this is the .htaccess code to use:

redirect 301 /oldfolder/oldfile.htm http://www.websitesinaflash.com/new.htm

There are three parts to this redirect (make sure you put 1 space in between each element):

1) “redirect 301”: This declares that you are doing a redirect, and that the code is 301: Permanent Redirect.

2) “/oldfolder/oldfile.htm”: This declares the page you want to redirect from.

3) “http://www.websitesinaflash.com/new.htm”: This is where you want the page to redirect them to.

This is useful when you have renamed pages, and want to make sure google knows where your new pages are, and also any visitors that would be directed to that old page will automatically be directed to the new page.

But what about directing an entire folder or site to another folder or site?
You’ll have to wait for next post. =]