Rewriting URLs when a WP post title is involved
December 19, 2010 6:44 AM   Subscribe

I'm moving a blog from a CMS (s9y) to WordPress, and obviously want to keep the URLs for entries intact. Can I get a hand with a silly htaccess + WordPress issue?

In short, I'm not sure how best to write the RewriteRules for this situation. I also think WP needs to be involved.

The blog I'm working on has one entry per day, always, and the existing URLs from s9y are:

domain.com/archive/2010/12/19/

The new URLs in WP will be:

domain.com/2010/12/19/post-title/

So I need a 301 from the old URL style to the new one, *and* I need WP to pass along the entry's name to the URL. Plugins or straight htaccess rules would be helpful.
posted by hijinx to Computers & Internet (6 answers total)
 
Go to the permalinks and use the Custom Structure option. Use "/%year%/%monthnum%/%day%/". You don't even need to mess with the htaccess file to get it to work. Although depending on how the export/import goes you may need to go back and edit post dates.
posted by theichibun at 6:52 AM on December 19, 2010


Damnit, that's what I get for answering without testing first. http://wordpress.org/extend/plugins/simple-301-redirects/ is a plugin that will handle redirects. WordPress already has an option in the permalinks section where it has the exact structure you want to use for your URLs.

There are a lot of plugins. I picked the link for that one because of the almost 5 star rating.

Also, my method from my precious post won't work because it takes you to a page that lists all of the post for that day. Clicking the link for the individual post then takes you to a list of posts for that day. A bit repetitive, and not exactly useful unless you display the full post on the archive and have no way to comment or anything since you'll never get to the actual post page. If that's fine with you then it will work. But I'm guessing that it won't.
posted by theichibun at 7:05 AM on December 19, 2010


I guess the question is, is there a straightforward way to change the "daily archive" page (the one which will have a link to just one blog entry in my case) to redirect to the entry directly?
posted by hijinx at 6:07 PM on December 19, 2010


<?php
	// paste this into the top of your theme's archive.php,
	// before you call get_header() or anything else
	if (is_day()):
		// get the first post of that day
		if ( have_posts() ) : while ( have_posts() ) : the_post();
			// this really does assume that you have only one post per day
			// if it doesn't, then you may get unexpected results
			$url = get_permalink();
			wp_redirect( $url, 301 ); exit;
		endwhile; else:
			print "<!--there was no post on this day-->";
		endif;	
	endif;
?>

posted by artlung at 8:37 AM on December 20, 2010


As a follow-up, artlung's answer worked. I ended up using a really simple htaccess rule to strip "archive" out of incoming URLs that followed that format.

Good stuff, folks - thanks!
posted by hijinx at 7:35 AM on December 21, 2010


Glad I could help hijinx!
posted by artlung at 9:26 AM on December 21, 2010


« Older Where to go, how to get there?   |   Rocks with eyes!? Newer »
This thread is closed to new comments.