Rewriting URLs when a WP post title is involved
-
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.
-
Answer:
<?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;?>
hijinx at Ask.Metafilter.Com Visit the source
Other answers
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.
theichibun
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.
theichibun
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?
hijinx
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!
hijinx
Glad I could help hijinx!
artlung
Related Q & A:
- How To Sort a GridView Column When a Header Is Clicked?Best solution by Stack Overflow
- May I use the title of Stack Overflow questions as my blog post title?Best solution by Meta Stack Overflow
- How to get tags in a wordpress post?Best solution by Stack Overflow
- What is a creative CD title?Best solution by noiseaddicts.com
- What does a private post on Tumblr mean?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.