I created a wordpress site and hosted on nginx server, and settings-> Permalinks and clicked save changes. This creates a .htaccess file on the site root.

On Apache server it's logical and worth creating an .htaccess file, but what it has to do with nginx server?? Is it safe to delete the .htaccess file from the root of my website??

1 Answer 1


WordPress tries to detect the webserver's type by peeking into the global $_SERVER['SERVER_SOFTWARE'] variable.

The Apache check is:

$is_apache = (strpos($_SERVER['SERVER_SOFTWARE'], 'Apache') !== false 
    || strpos($_SERVER['SERVER_SOFTWARE'], 'LiteSpeed') !== false);

and the Nginx check is:

$is_nginx = (strpos($_SERVER['SERVER_SOFTWARE'], 'nginx') !== false);

You should therefore first check out:

var_dump( $_SERVER['SERVER_SOFTWARE'] );

to see if it's correct.

Here are some alternative workarounds:

It's also possible to avoid the .htaccess file being created with:

add_filter( 'flush_rewrite_rules_hard', '__return_false' );

to avoid the save_mod_rewrite_rules() to run.

Within the save_mod_rewrite_rules() function, there's a got_mod_rewrite() check before the .htaccess is updated. It's also possible to use:

add_filter( 'got_rewrite', '__return_false' );

to avoid insert_with_markers() to run that writes the .htaccess file.

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.