• I have this peculiar problem with my WordPress (v2.2.1) installation on my website.

    When I edit a page (and only a page, this does not apply to posts or attachments) and save it, the WordPress permalink structure gets messed up, resulting in a 404 Not Found showing up for all permalinks. Physical files are normally accessible.

    First, I tried to reset my permalinks to the default value (?p=123 URL’s). That resulted in the question whether I really wanted to change the permalink structure to an empty string, as can be seen here.

    Second on the list: the .htaccess file. Since WordPress can’t write to it, that couldn’t be the problem. Nevertheless, I checked it anyway, and found it to be OK (works perfectly on my local server and also on my site when everything is as it should be).

    So it had to do with WordPress itself. I took a look at the options table in WordPress’s database, and found two interesting rows: permalink_structure and rewrite_rules. The first one is simply that what’s been chosen in the Permalinks admin panel. The second is a lot of abracadabra that I assume WordPress uses to determine what page/post to show.

    And that’s exactly where I found the problem was. I used phpMyAdmin to paste the value from my local WordPress installation (which is a mirror of my website, but works just fine) into that row, and voila, things were back to normal.

    So I assumed it was just a glitch and everything was OK again. Well, it was not. Next time I edited a page, boom, same problem. Fortunately I now know how to fix it, so in a matter of minutes things were working again.

    Next step was to deactivate all plugins, revert to the default WordPress theme and try again. Same problem.

    Then, I exported my site contents through the Export admin panel, dropped all the tables in WordPress’s database, re-ran wp-install.php, imported my site contents then and reset all options to my needs. Problem persisted.

    As a final and desperate step, I trashed all WordPress related files from the server except for wp-config.php, my theme and my plugins. Then I uploaded a freshly downloaded copy of WordPress back to the server and repeated all the steps above. No luck, problem still persists.

    I’m out of ideas now, short of diving into the core of WordPress to figure out what goes wrong. But that step is a just a little too steep for me.

    Right now, I avoid editing pages as much as possible, and when I have to, I just paste the rewrite_rules from my local WordPress installation directly into the database, but you’ll understand that having to do that over and over again quickly gets pretty awkward.

    So, if anyone can help me out with this one, it would be much appreciated.

Viewing 13 replies - 1 through 13 (of 13 total)
  • Thread Starter Colin Helvensteijn

    (@raptornl)

    I’ve done some more DB digging and found two other rows in the options table: page_attachment_uris and page_uris. They’re in the same format as rewrite_rules, but a lot shorter. As said before, I’m pretty confident that WP uses all that gibberish to contruct regular expressions with which in turn will yield the requested post/page/whatever (so long as those rewrite rules aren’t messed up). What those page_attachment_uris and page_uris tables do exactly, I’m not sure, as the same information already seems to be in the rewrite_rules row.

    What I still haven’t figured out is what exactly goes wrong, other than the fact that those rewrite rules get screwed on every page edit.

    I’ve also begun going through the core of WP, to find out what exactly it does when writing/editing pages and where it could go wrong, but it’s fairly more complex than any PHP code I’ve ever written and it takes some time to even make heads or tails of it.

    So, any help would still be very, very welcome, because as it looks now, I don’t think I’m going to find the problem myself anytime soon, let alone fix it.

    P.S. Perhaps the output of phpinfo() could be useful to anyone looking at this problem.

    Thread Starter Colin Helvensteijn

    (@raptornl)

    I’m not sure, but I think it has to do with the fact that my WP files are in another directory than the index.php file (index.php is in the site root, WP files are in /wp).

    I noticed that when I post an article in my blog, “Site admin” links, “Edit post/comment” links and the likes point to /wp-admin/ whereas they should point to /wp/wp-admin/.

    So if WP indeed thinks that its files are in the siteroot when posting, it kinda figures that it messes up those rewrite rules when posting/editing a page, becase it seems only then it recreates them.

    Am I making any sense? Is anyone reading this at all? I’d still appreciate some help here…

    hey…i’ve been reading, but unfortunately have no clue either. I’m experiencing the same problem although my WP install is in the site root. Posts work fine, just not pages (except for Archives). The most frustrating thing is i’m running several sites on WP and only one of them has this problem.

    After hours of reading and researching to try and fix this I still can’t get it working. I think it’s definitely a mod-rewrite issue.

    *sad*

    Thread Starter Colin Helvensteijn

    (@raptornl)

    Hi Dreamshop

    Well, at least it’s good to know I’m not the only one with this problem. Then again, makes it all the more curious why I just can’t seem to find anything about it. Tried these forums, tried Google, nothing.

    I could perhaps accept it if it was only me, but if you have the same problem, it stands to reason we’re not the only ones. So why can’t I just find anyting?

    the really annoying part is that the WP docs state that with permalinks the htaccess should be updated whenever you add a new page…but there’s NO explanation about what formula these should be in if you have to add them manually.

    i’ve tried numerous things such as deactivating all plugins, using default ‘ugly’ links etc. I still get a 404 error for all pages, both old and any new ones I try to add.

    Also…I’ve noted that you mention a rewrite rule in the wp_options database table but I can’t don’t see this in any of my installs?

    Thread Starter Colin Helvensteijn

    (@raptornl)

    WordPress has changed the way it handles request recently. In WP 1.5, all rewrite rules were stored in the .htaccess file. WP 2.2 (I’m not exactly sure when they changed this) has a simple rewrite rule in its .htaccess file that rewrites every request to a non-existing physical file to index.php, and then uses the rewrite rules from the database to determine what to do with the request.

    So when anyone requests a page from your site, Apache will try to find a physical file matching the request, and if it can’t, it rewrites the request to WP’s index.php, and WP uses the original request URI (which it gets from Apache) to try to find any matches, and if it can’t, it’ll throw a 404 at you.

    So these rewrite rules in the database are for some reason messed up when posting or editing a page, causing WP to be unable to find any match for any request whatsoever, and thus always spits out a 404.

    I’m not exatly sure why WP still tries to recontruct the .htaccess file everytime I post or edit a page, because since all those rewrite rules are now in the database, it is no longer nessecary.

    well i still have this problem…my next step is to setup a copy of the site with a fresh install on a different hosting account. i’m wondering if it just comes down too WP not playing nice with the host apache or php setup.

    one other thing this install uses is Gallery2. so it could be that.

    still testing.

    Thread Starter Colin Helvensteijn

    (@raptornl)

    I’m going to move to another host soon, too. Going to do a fresh install, and I hope I’m rid of this problem then.

    I had this exact same problem as well… I lived on backups for a couple months and couldn’t get it to work.

    Then I did some hacking and figured it out. First I added the plugin:

    function fix_slash($string, $type) {
      global $wp_rewrite;
      if ($wp_rewrite->use_trailing_slashes==false && $type != 'single')
        return trailingslashit($string);
      return $string;
    }
    
    add_filter('user_trailingslashit', 'fix_slash', 66, 2 );

    that is a bit of a custom job from this forum, but it works at adding a trailing slash to links…

    Now whenever I want to edit a page I backup my sql, then I have to go edit /wp-includes/rewrite.php specifically

    function get_category_permastruct() {
    		if (isset($this->category_structure)) {
    			return $this->category_structure;
    		}
    
    		if (empty($this->permalink_structure)) {
    			$this->category_structure = '';
    			return false;
    		}
    
    		//if (empty($this->category_base))
    			//$this->category_structure = $this->front . 'category/';
    		//else
    			$this->category_structure = '/';
    
    		$this->category_structure .= '%category%';
    
    		return $this->category_structure;
    	}

    I just have to uncomment those 3 lines and it works perfect. BTW, I recommend DreamHost

    Thread Starter Colin Helvensteijn

    (@raptornl)

    Unnfortunately, that doesn’t work for me either. But my domain will be transferred to my new webhost within a few days, so I hope a fresh WP installation there will fix this…

    okay….so after doing a huge amount of testing I decided to try a different theme template and that fixed it. (DUH) So my problem was caused by some bad code in the design template. Turns out the developer isn’t updating that template anymore so I’ve switched to another.

    Thread Starter Colin Helvensteijn

    (@raptornl)

    Well, doesn’t work for me since I already tried with the default theme on a completely fresh install. I think I can assume that at least that one should work fine.

    Thread Starter Colin Helvensteijn

    (@raptornl)

    Marked the topic as resolved. Since I moved to a new web host, I have no more problems.

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Rewrite rules messed up after page edit’ is closed to new replies.