[wp-hackers] Hack to prevent 404s

Brian Layman Brian at TheCodeCave.com
Tue Jun 13 16:57:49 GMT 2006


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
 



More information about the wp-hackers mailing list