[wp-hackers] Hack to prevent 404s

Computer Guru computerguru at neosmart.net
Wed Jun 14 07:22:37 GMT 2006


There is a plugin that does just that already. It changes any non-selected
wp-permalinks to 301 redirects to the real deal.
Try this link: http://neosmart.net/blog/?p=182
It'll redirect you to: http://neosmart.net/blog/archives/182 with a 301
header.

This is the plugin: http://fucoder.com/code/permalink-redirect/


Computer Guru
NeoSmart Technologies
http://neosmart.net/blog/

-----Original Message-----
From: wp-hackers-bounces at lists.automattic.com
[mailto:wp-hackers-bounces at lists.automattic.com] On Behalf Of Brian Layman
Sent: Tuesday, June 13, 2006 7:58 PM
To: wp-hackers at lists.automattic.com
Subject: [wp-hackers] Hack to prevent 404s

While checking out different permalink structures, my site was crawled by
several search engines.  And I am still getting traffic from those links.
I've been hard coding redirects into .htaccess for my most popular posts,
but it seems to me that I should not need to do this...

I decided it should be possible to get WordPress to process all of the built
in permalink structures (and one custom one that I tried), and here's what I
did to get this to work:

In classes.php, after this line:
		// Post
		$post_rewrite =
$this->generate_rewrite_rules($this->permalink_structure);
		$post_rewrite = apply_filters('post_rewrite_rules',
$post_rewrite);

I added these lines:
		$post_rewrite1 =
$this->generate_rewrite_rules('/%year%/%monthnum%/%day%/%postname%/');
		$post_rewrite1 = apply_filters('post_rewrite_rules',
$post_rewrite1);

		$post_rewrite2 =
$this->generate_rewrite_rules('/archives/%post_id%');
		$post_rewrite2 = apply_filters('post_rewrite_rules',
$post_rewrite2);

		$post_rewrite3 =
$this->generate_rewrite_rules('/Article%post_id%');
		$post_rewrite3 = apply_filters('post_rewrite_rules',
$post_rewrite3);

And then changed:
		$this->rules = array_merge($page_rewrite, $root_rewrite,
$comments_rewrite, $search_rewrite, $category_rewrite, $author_rewrite,
$date_rewrite, $post_rewrite);


To this:
		$this->rules = array_merge($page_rewrite, $root_rewrite,
$comments_rewrite, $search_rewrite, $category_rewrite, $author_rewrite,
$date_rewrite, $post_rewrite, $post_rewrite1, $post_rewrite2,
$post_rewrite3);

(BTW I do currently have a custom permalink structure. Which is what allows
it to get into this section of the code.  There is an if statement prior to
this that just drops you out of the section when you have a blank/default
permalink structure.)

Is there any reason why I should not do this?  I don't think the speed hit
will be that bad.  

Should something similar be a default WP option (a check box for processing
legacy/alternate/all default permalink structures)?

I KNOW I am not the only one that experimented with alternate permalink
structures for their blog... And many people probably ran them for more than
a day or two...

_______________________________________________
Brian Layman
www.TheCodeCave.com
 

_______________________________________________
wp-hackers mailing list
wp-hackers at lists.automattic.com
http://lists.automattic.com/mailman/listinfo/wp-hackers



More information about the wp-hackers mailing list