[wp-hackers] URL to jump to the single post of a day
Austin Matzko
if.website at gmail.com
Sat Feb 14 22:25:26 GMT 2009
On Fri, Feb 13, 2009 at 11:41 PM, <jidanni at jidanni.org> wrote:
> While converting a static HTML site to WordPress, I have fifty URLs to
> redirect via .htaccess. I should probably just hardwire them all in,
> but I noticed for WordPress if there is only one match for day, etc,
> the name gets expanded:
> $ HEAD -Sd http://localhost/articles/index.php/2002/10/02/a
> HEAD http://localhost/articles/index.php/2002/10/02/a --> 301 Moved Permanently
> HEAD http://localhost/articles/index.php/2002/10/02/a-government-out-of-control --> 200 OK
> So I was thinking maybe instead of 50 hardwired lines, I could just
> get away with one:
> RedirectMatch (articles)/(\d{4})(\d{2})(\d{2})\.html$ http://localhost/$1/index.php/$2/$3/$4
> which gets to the archive for that day, good enough, but as my site
> never had more than one article per day, I am looking for the magic
> wildcard character I could add to the end to jump straight to the article.
> I could add "/a", but not all my articles start with "a". OK, never
> mind. I'll just hardwire them all in. That way I can just issue the
> definite 301 redirect in one shot.
Since you have just one article per day, something like the following
should work:
In .htaccess:
RedirectMatch (articles)/(\d{4})(\d{2})(\d{2})\.html$
http://localhost/$1/index.php/$2/$3/$4?singleredirect=1
In a plugin:
add_action('template_redirect', 'redirect_old');
function redirect_old() {
if ( is_day() && ! empty( $_GET['singleredirect'] ) && have_posts() ) {
the_post();
wp_redirect(get_permalink(), 301);
exit;
}
}
More information about the wp-hackers
mailing list