Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Custom permalinks for pages break(404) after saving a page WordPress

  • SOLVED

If I use custom permalinks (any other format besides the default ?p=123), everything works fine until I edit and save a page. Once any page is edited and saved, going to any pages custom permalink results in a 404. This only happens when editing and saving a page. If I edit and save a post or a custom post type everything is fine.

The server the site is on has mod-rewrite enabled. The .htaccess file is CHMOD 644 and says:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress


I have tried disabling all plugins, deleting the functions file, renaming the .htaccess file so it creates a new one, and using different permalink structures. Nothing seems to fix it.

When this happens, if I switch to the default permalinks and back to custom again, all the pages come back. But this is a client's website and it wouldn't look so good if I told her she had to do this every time she wants to edit a page.

I switched to the standard Twenty Ten Theme and it no longer 404'd all the pages if I edited and saved one while using custom permalinks. This makes me think it is something in my theme files that is triggering this (but it's not the functions page since I deleted it and it was still doing this).

The site is currently live here: [[LINK href="http://seejanedirect.com"]]http://seejanedirect.com[[/LINK]]
You can see it's currently using the default permalink structure since it's the only thing that works right now.

Please help!

Answers (5)

2011-06-27

Luke America answers:

Thousands of WP installations have been impacted by a custom permalinks bug that manifests itself after upgrading to 3.1+. I've written a corrective plugin that you can read about here: [[LINK href="http://wpcodesnippets.info/blog/wcs-custom-permalinks-hotfix.html"]]WCS Custom Permalinks Hotfix[[/LINK]]. That page also offers various solution possibilities to avoid having to implement the plugin.

Additionally, as Denzel Chia pointed out, the following superfluous 'ignore rewrites for index.php' line could be commented out in your .htaccess file:

RewriteRule ^index\.php$ - [L]
to
#RewriteRule ^index\.php$ - [L]

Moreover, since your issue does not manifest itself when using the 2010 theme, there is, as you deduce, a high probability that your preferred theme includes some code which spawns the 404's. As such, I'd speculate that your theme includes the following line in one of it's files, normally the functions.php file. If you find it in any theme folder file (including subfolders), comment it out:

$wp_rewrite->flush_rules();
to
//$wp_rewrite->flush_rules();

(update start) I've perused your theme's file and could not find the code line just mentioned. Thus, I'd speculate that somehow that .htaccess is causing the issues -- it shouldn't. Or, you're a victim of the 3.1+ permalinks bug. Also, you stated that you have no plugins active. Do you have a mu-plugins folder?(update end)

If you can not find this line in any file in your theme's folder tree, I have another question. Does the bug manifest itself when using any other themes on the site?

Also, after making any changes be SURE to clear your browser's cache to force a fresh page/site load. You might also pull it up in a browser that you don't normally use, since it wouldn't have the site in your local cache.

Plus, if you're using a server cache plugin, be sure to not only deactivate it for testing, but also clear its cache.

The aforementioned plugin should repair the issue regardless of what the specific cause is. But, if you can fix it by striking a single line of culprit code, that's a more viable solution.

If you do have to use the plugin, you'll note that your uri's in the address bar look different. Nonetheless, regular links will work and it is SEO safe for existing backlinks from other sites, search engines, etc. This uri adjustment is made internally to utilize the base structure. Ergo, it would be safe in perpetuity, if need be.


Lindsey comments:

Hi Luke, thanks for the thorough reply. I did what you said and commented out the extra line in the htaccess file, that didn't fix it. I searched through all the theme files for:

$wp_rewrite->flush_rules();

Didn't find it anywhere. So I installed your plugin, but to my dismay that didn't fix it either! I'm still getting a 404 on pages after I save them while using any custom permalink structure except for:

/index.php/%postname%

For some reason that one works.

I'm not using multiple installs of WP by the way, so no MU plugins folder.
I'm not using a server cache plugin, nor any plugins that would change the names of posts/pages/categories.

Like I said in my original post, I switched to the 2010 theme and didn't have any permalink issues. I also just switched to another theme I just downloaded and that theme didn't have any permalink issues either. So it has to be something in my themes files that is causing this. But it's not in the functions file since I already tried deleting it and the permalink issue still existed.


Luke America comments:

It's odd that your 2010 and other themes handle custom permalinks correctly. I did check the files in your current theme and could not locate a culprit. Before proceding, make sure that you don't have any .htaccess files in your WP paths other than in the root folder.

If it were not for this, I'd recommend the following possible updates. In order for it to not be mandatory for 'index.php' to be in the WP uri on a LAMP server, you must have 'AllowOverride' and 'mod_rewrite' enabled.


1. AllowOverride
Put this line at the top of your .htaccess file:

AllowOverride All


2. mod_rewrite
In your server's httpd.conf file (usually in '/etc/httpd/'), uncomment

#LoadModule rewrite_module modules/mod_rewrite.so
to
LoadModule rewrite_module modules/mod_rewrite.so

and then reboot the server.


Lindsey comments:

1. Adding "AllowOverride All" to the top of htaccess created an "Internal Server Error" when I visited the site.

2. I can't find the httpd.config file, it isn't in /etc/ (there is no /httpd folder in 'etc')...


Luke America comments:

Okay, look in the /conf/ folder for httpd.conf.

Since, I'm speculating loosely that we have a server configuration issue, try each of the following separately. Insert at the top of your .htaccess file:

Options +FollowSymLinks
or
Options -MultiViews

I'm curious, is your host 1and1?


Lindsey comments:

There isn't a conf folder either...

I searched in the cpanel file manager for "httpd.conf" and came up with nothing. I pretty much am an idiot when it comes to server side issues, but it seems like I should have an httpd.conf file somewhere right?

The host is PrimeHost.

I tried adding both those 'Options' items to htaccess one separately and neither one did anything


Luke America comments:

Frankly, I wouldn't label myself an expert on server configuration issues. It's basically a trial-and-error learning process. I've just had more trials and errors. :)

One aspect of this issue that really puzzles me is that your permalinks work perfectly with any theme except your preference. And, I can not find any code in it which could cause this issue. But, I'll look again shortly.

Permalinks that require 'index.php' to be in the path like this are called 'PATHINFO permalinks'. They're identical to 'pretty permalinks' with that one exception.

Generally this variation is manifested only with LAMP sites that don't have 'mod_rewrite' (very rare) ... or don't have it enabled in 'httpd.conf'. Could you check with your host to ensure that it is enabled?

Also, you might check here: /usr/local/apache/conf

Remember:

#LoadModule rewrite_module modules/mod_rewrite.so
to
LoadModule rewrite_module modules/mod_rewrite.so

and then reboot the server.


Luke America comments:

Also, if you have command line access, the following should reveal where 'httpd.conf' is located:

httpd -V


Lindsey comments:

I don't have command line access (or maybe I do but it's not working using Putty) and I still cannot find the httpd.conf file. I just emailed customer support for the host and asked them where the file was, if mod_rewrite was enabled (I asked a few months ago for something else and they said yes), and asked whether the server had Apache installed. I'll let you know what they say.


Lindsey comments:

This is the response I received:
<blockquote>You don't have access to httpd.conf file as per security concerns. But You can do configure your domain by using .htaccess under your public_html. The .htaccess file is just like a httpd.conf for your domain.

Also We are running Apache version 2.2.17 in this server and mod_rewrite has been enabled on this server. please have a check now.

============
root@navigator [~]# httpd -V
Server version: Apache/2.2.17 (Unix)

root@navigator [~]# httpd -l|grep mod_rewrite
mod_rewrite.c
</blockquote>


Luke America comments:

Here's a quick test with your .htaccess file.

Comment these:

<IfModule mod_rewrite.c>
to
#<IfModule mod_rewrite.c>

and

</IfModule>
to
#</IfModule>

If you get a server error on your next page load, you most likely do NOT have 'mod_rewrite' enabled. It's worth a check, even though they're reporting that it is enabled.

Also, I've checked on this line: RewriteRule ^index\.php$ - [L]

It's a new one with WP. It should be okay to UNcomment it.

Finally, my second search reveals no code in your theme files that could cause this issue.


Lindsey comments:

I commented out what you said to and it didn't cause any errors, everything worked fine. Any other ideas?


Luke America comments:

Could you double-check to make certain there are no plug-ins active? It looks like you have the 'uBillboard' and 'cufon-fonts' plugins active.

Also, did you determine if you have a 'mu-plugins' folder?

Are you using the latest version of WordPress, 3.1.3?

BTW, this issue also manifests itself with your RSS feed.

Here's a possibility that you'll need to tweak the directory path to your WP installation. Put this at the top of your .htaccess file.

<Directory /YOUR/SERVER/PATH/ > #This is the directory where your website is located.
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>


Lindsey comments:

I definitely have all the plugins enabled right now. I was saying that I have disabled the plugins previously and this issue still persists. I also have switched to other these with all the plugins enabled and the permalinks work fine so it's not the plugins.

I don't have an MU plugins folder.

Yes it's using version 3.1.3.

I added that to my .htaccess file (with server path) and it gave me a 500 internal server error.


Luke America comments:

In that .htaccess snippet, did you set the path for your server?


Lindsey comments:

Yes I did, as long as its the path to where I installed wordpress correct? Which in this case is the root directory. /home/seejaned/public_html


Luke America comments:

Yes; that would be the one. But, it should have a trailing slash.

I would be certain that you have a 'mod_rewrite' issue if it were not for the fact that you only have this error in your current theme. Maybe ... instead of having a code segment that's causing the problem ... it's missing a line of code that should be there.

But ... alas ... our time clock is about to run out ... and I really don't have a good, workable path for us to pursue at this juncture.

Maybe you could take an existing theme ... copy and rename it ... and do one of two procedures: (1) comment out suspicious lines of code or 'return' immediately from some functions until you can 're-create the bug', or (2) modify that copied theme to match your current one.


Lindsey comments:

Before posting the question, I also tried removing all jquery code and pretty much everything in the header to see if that would fix it, but it didn't. It seems like the likely hood of fixing this is pretty slim and I've already spent so many hours trying to. Plus this project should have been done months ago and the client has dragged it out. I think I'm just going to have to tell her to deal with /index.php/%postname%. It isn't as bad as the default permalinks.

You win the money by the way, obviously since you have been a huge help even though it's not fixed. At least I know what isn't causing it. :)


Lindsey comments:

You are not going to believe this, I actually fixed it thanks to you suggesting copying the theme and messing with the copied version. I just started commenting out segments of the functions code and finally figured out it was this part of the code that was causing it:



register_taxonomy(
'video_type',array ( 0 => 'video',)
,array( 'hierarchical' => true, 'label' => 'Type','show_ui' => true,'query_var' => true,'rewrite' => array('slug' => ''),'singular_label' => 'video_type') );


So I deleted it and installed the "Custom Post Type UI" plugin (which is originally generated the custom taxonomy code) and re-created the taxonomy. It's option (and in beta) to copy the code it can generate to the functions file. You can also just have it do it's thing in the background which works file. Copying the code to the functions file breaks permalinks apparently.

But it's fixed!!! YA! Thank you so much!!

2011-06-26

Utkarsh Kukreti answers:

Would it be possible to have a look at the theme files?


Lindsey comments:

Here's a link to a directory with a copy of the theme files in it. The index1.php file is really index.php but had to be renamed for obvious reasons in this situation.

[[LINK href="http://seejanedirect.com/themefiles/"]]Theme Files[[/LINK]]


Utkarsh Kukreti comments:

You'll need to zip them up or rename php -> txt, as PHP files are parsed by the server, and cannot be seen like that :)


Lindsey comments:

Oops sorry about that. Here's the zipped: [[LINK href="http://seejanedirect.com/themefiles/themefileshelp.zip"]]http://seejanedirect.com/themefiles/themefileshelp.zip[[/LINK]]

2011-06-27

Romel Apuya answers:

try adding index.php before the custom structure of the permalink..something like.. /index.php/%postname%/


please read this rules regarding [[LINK href="http://perishablepress.com/press/2006/06/14/the-htaccess-rules-for-all-wordpress-permalinks/"]]htaccess[[/LINK]].


Lindsey comments:

That works, but I'd really like the URL to pages to be /%postname% only, without index.php. Can you think of any reason why index.php would work but any all other custom permalink structures do not?

2011-06-27

Nilesh shiragave answers:

your website is running on IIS server?


Lindsey comments:

Apache

2011-06-27

Denzel Chia answers:

Hi,

This is the standard WordPress htaccess for root install


# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress



Not sure why yours got an extra rule?


RewriteRule ^index\.php$ - [L]


Perhaps removing this will solve your problem.

Thanks.
Denzel