简体   繁体   中英

Can this code cause a “500” internal server error?

A few of my customers are reporting that they are getting "500" Internal Server errors lately. I believe it might be caused by various plugins they are using but each time, the hosting company (multiple hosts) are saying that the htaccess file had to be replaced to fix the issue.

I'm submitting the code below from my custom theme because its the only place where I trigger an htaccess write. And I want to be sure that there are no problems here that could cause an issue that might contribute to the 500 errors...

if (file_exists(ABSPATH.'/wp-admin/includes/taxonomy.php'))
    {
    require_once(ABSPATH.'/wp-admin/includes/taxonomy.php');
if(get_option('permalink_structure') !== "/%postname%/" || get_option('mycustomtheme_permalinks') !=="/%postname%/")
    {
    $mycustomtheme_permalinks = get_option('mycustomtheme_permalinks');
    require_once(ABSPATH . '/wp-admin/includes/misc.php');
    require_once(ABSPATH . '/wp-admin/includes/file.php');
    global $wp_rewrite;
    $wp_rewrite->set_permalink_structure($mycustomtheme_permalinks);
    $wp_rewrite->flush_rules();
    }
    if(!get_cat_ID('topMenu')){wp_create_category('topMenu');}
    if(!get_cat_ID('hidden')){wp_create_category('hidden');}        
    if(!get_cat_ID('noads')){wp_create_category('noads');}
    }
if (!is_dir(ABSPATH.'wp-content/uploads')) {
    mkdir(ABSPATH.'wp-content/uploads');
}

The code first checks to make sure taxonomy.php is present, since the wp_create_category calls require it. It also checks the existing permalink settings and if they are not set according to my anticipated parameters, I execute the permalink rewrite code you see there. Its this code that, I'm fairly certain, creates an htaccess edit. I want to be sure that this is a sound bit of programming and not likely to cause sporadic internal server errors...

EDIT: In One Case, the user has the following plugins in all his sites...

  • AIO SEO
  • cbnet ping optimizer
  • contact form 7
  • easy privacy policy
  • Exec-PHP
  • Free Traffic Getting SEO Plugin
  • google sitemap generator
  • pretty link
  • ReviewAZON
  • Sociable
  • StatPress ReLoaded
  • Web Traffic Genius Pro
  • WP DB Backup

The mkdir call will definitely fail if wp-content is not writable, the same goes for the permalink edit - if .htaccess is not writable then it will fail and might cause a 500 error (depending on how Wordpress implements this). Another possible problem could be that your .htaccess changes corrupt some other setting in .htaccess that is needed by one of the other plugins.

In any case : looking at the Apache error log and logging PHP errors should be enough to find the actual source of the problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM