3

I have two identical copies of the same site on two different webhosting companies (besides the actual domain of course). One of them works all the time with pretty permalinks and the other works fine a day or so, but then all of a sudden it does not work and the permalink gives a 404 file not found, but only when viewing a singe custom post page, named single-<cpt-name>.php in the theme folder.

When I go into admin / Permalink page - the site starts to work again (with the custom post page showing again)

My thoughts are that this must be server-related. The site that is working all the time has PHP 5.4 and the one that is not working all of the time has PHP 5.5, but I don't think the version of PHP is the issue. Both sites have WP 3.8.

I'm using a cacheplugin called WP Supercache, but that doesn't seem to be the issue because the site works again with cpt without flushing the cache (after viewing permalinksettings in admin)

I'm using permalink-structure: /%postname%/

I'm wondering how I could debug this? In order for me to debug this I want to know what happens (programmatically) when permalink-settings are updated? I think that the .htaccess in the root-folder (same as wp_config.php) is changed. (based on some reading) Is this correct?

I'm wondering if some plugin can cause the issue? (a plugin that somehow messes up pretty permalinks somehow)

My .htaccess looks like this (when working):

# 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

2 Answers 2

1

You're correct, when you update the permalinks, the htaccess file also updates.

When you create or update a "pretty" permalink structure, WordPress will generate rewrite rules and attempt to insert them into the proper .htaccess file. If it can't, it will say something like "You should update your .htaccess now" and print out the rules for you to copy and paste into the file (put them at the end).

Source: WordPress Codex.

First, verify that the htaccess file has the appropriate lines. Then verify that your hosting server has all the requirements (apache, mod_rewrite etc). Finally, disable all plugins and see if it works like that. If it works, enable one plugin at a time to find the one that's causing the issue.

3
  • The hosting company must have those requirements, else it wouldn't work at all? I've updated my question with my actual .htaccess. I really can't disable all plugins one at a time. That would mean that I would have to have a lite site down for a few days just to checks what's the issue. I don't think my customer would agree to that... Commented May 10, 2014 at 17:41
  • The htaccess file has the correct lines. You can verify if the hosting company meets the requirements by doing a php_info(). However, most likely this issue is caused by a plugin. If you can't have the website offline, make a copy (search for Duplicator plugin) and work on a dev server. Commented May 10, 2014 at 17:46
  • I don't think it's related to plugin because I have exactly the same plugins on another server which works all the time. What could a plugin do to mess this up? The only thing I would see it that a plugin changed the htaccess-file? I read now that The FollowSymLinks option must be enabled. Could this be an issue if the hosting company doesn't have this as default? Commented May 10, 2014 at 17:51
1

When the permalink got broken this time, I checked for any changes in the htaccess-file. There was no changes. When I went to the permalink-settings page in admin, and reloaded the site in the browser everything worked, BUT no changes were made to htaccess now either. So there must be something else going on that updates the use of permalink-settings somehow.

So I digged further...

I was actually lying to you guys (not intentionally though). It wasn't identical copies of the site that I thought it was. I compared all files in the two sites... There were one small difference, that really seemed to matter. I had singe-<cpt>.php in the parent theme on the development site (I copied that to file to the dev-site a while ago), but not on the live site.

I'm using a child theme and having the oxygen theme as parent theme.

The structure of the live site was like this: (worked for a while after updating permalinks)

- themes
-- oxygen
-- childtheme
--- single-<cpt>.php

The strucutre of the development site: (worked all the time)

- themes
-- oxygen
--- single-<cpt>.php
-- childtheme
--- single-<cpt>.php

For some reason singe-<cpt>.php isn't found everytime when just putting it in childtheme. It works for a while (A day or so. I haven't been able to figure when exactly). For some reason Wordpress only searches for single-<cpt>.php in parent theme (oxygen) at certain times.

So now I have this structure on the live site:

- themes
-- oxygen
--- single-<cpt>.php
-- childtheme
--- single-<cpt>.php

and it has been wokring since I made this change.

This issue only seems to applied to single-<cpt>.php, not for example taxonomy-<name of taxonomy>.php

I don't know if this is a core WP issue or it is a Oxygen theme issue, but I really have no time right now for digging deeper into it. If someone wants to explore the issue I would be really interested in where the actual issue lies.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.