Website Designers and Webmasters

Dedicated to all the tasks Webmasters, Website Developers and Website Designers find themselves facing.

By: Ashton Sanders

WordPress: Redirect Blog to First Post

Apr 12 2010

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:

<?php
/*
home.php (Blog Home Page):
Redirect To First Post
*/
if (have_posts()) {
while (have_posts()) {
the_post();
wp_redirect(get_permalink());
}
}
?>

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.

Enjoy,
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.)

By: Ashton Sanders

.htaccess 301 Redirect: Moved Permanently

Mar 16 2007

Filed under: htaccess

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. =]

Enjoy
Ashton

RSS

Where Am I?

You have found the semi-coherent ramblings of Ashton Sanders: a website designer, developer and webmaster. This is primarily Ashton's place to save notes about techniques and things that he learns in his never-ending conquest of the internet. Hopefully it's coherent enough to be useful to you too.

Subscribe:

Enter your email to get automatic emails whenever Ashton posts on the blog.

Email:

Advertisers:

Email Marketing $19/Month! OIOpublisher Learn how to make Money from Blogging Hillarious, High-Quality Shirts for $6/each Great Book Keeping and Invoicing Software Advertiser Here

Tags and Categories

Links

Blog Roll