1

I installed WordPress on Ubuntu 22.04 and when I tried to write a post or edit the default post that comes pre-installed I got an error message:

The response is not a valid JSON response

After a lot of googling and also seeing there was no .htaccess file in the root directory, I thought that the reason for this was that in the apache configuration file I had AllowOverride None. I made a directory specific (to the root directory of my WordPress installation) AllowOverride All and restarted apache. Now I can edit and make new posts without the error message.

I assumed that when I looked at the contents of the root directory I would see a .htaccess file but there is not one there (I have looked for hidden files). I searched the sub directories and did find one .htaccess file at ./wp-content/plugins/akismet/.htaccess which was created or modified in July. Also Akismet seems to be to do with spam so I thought it was unlikely to be anything to do with the error I had been getting when I tried to create or edit posts.

Although my WordPress installation now appears to be working, I would like to know why the AllowOverride directive change, which seems to be very much to do with enabling .htaccess files, solved the problem but did not result in a .htaccess appearing in the root directory. I thought I had read that WordPress requires a .htaccess file in the root directory.

I would be very interested in understanding what the situation is in relation to .htaccess files and WordPress and the results I obtained by changing the AllowOverride directive.

3
  • 1
    "I made a directory specific (to the root directory of my WordPress installation)" - Not sure what you mean by that? Simply making an arbitrary subdirectory in the root to which you AllowOverride All (which is what that sounds like?) doesn't make much sense?
    – MrWhite
    Jan 7, 2023 at 0:41
  • 1
    As @MrWhite points out, changing the server config won't automatically create a .htaccess file. You can add one, though, and here's what WordPress recommends you put in your .htaccess file.
    – Pat J
    Jan 7, 2023 at 1:55
  • I have just removed the AllowOverride All directive from my config and restarted apache. Now I am able to make and edit posts. It must have been something else I did (or that happened) which solved the problem. Jan 7, 2023 at 10:24

1 Answer 1

1

I would like to know why the AllowOverride directive change, which seems to be very much to do with enabling .htaccess files, solved the problem

If there are no .htaccess files then adding AllowOverride All in the server config is not going to do anything. As you suggest, AllowOverride essentially enables .htaccess files to be processed (if any exist along the file-path). Specifically, it allows directives in .htaccess to override directives that might have been defined in the server config (in a directory context).

I thought I had read that WordPress requires a .htaccess file in the root directory.

You can run WordPress without a .htaccess file. However, to use "pretty permalinks" (ie. without /index.php being present in the URL) you do need a .htaccess file (on Apache or LiteSpeed servers).

Although, having said that, everything you can do in .htaccess can be done in the main server config (and much more), so you don't strictly need a .htaccess file at all.

1
  • Thanks! It is very useful to know I can put the directive on the main server as Apache recommend that where possible. I thought WordPress might need to write to the .htaccess file and / or create it in the first place which I could see might be possible whereas WordPress could not write to the main server config. Clearly I was pretty confused but slightly less so now... Jan 7, 2023 at 10:28

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.