Fixing WordPress “404 Object Not Found” Errors on a Mac OS X Local Server Environment

F

Installing WordPress on a local server environment is fairly straight forward. There are numerous guides to be found on the Internet that’ll walk you through each step.

However, if your local server environment is running on a Mac, the local Apache server may have some difficulty serving WordPress posts and pages resulting in Error 404 Object not found! errors. These errors can often be attributed to the use of custom or so-called pretty permalinks.

The default permalink structure in WordPress is http://domain.com/?p=123. Any other structure requires an .htaccess file containing mod_rewrite directives to re-write the permalink URLs correctly. The kind of directives that are allowed in .htaccess files are controlled by the Apache server’s configuration file: httpd.conf.

The configuration file for the Apache server that ships with Mac OS X is /private/etc/apache2/httpd.conf. The directory where web pages are stored, known as the document root, is set to /Library/WebServer/Documents by default and in the Mac OS X Apache server is configured as follows:

#
# This should be changed to whatever you set DocumentRoot to.
#
<Directory "/Library/WebServer/Documents">
    #
    # Possible values for the Options directive are "None", "All",
    # or any combination of:
    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    #
    # Note that "MultiViews" must be named *explicitly* --- "Options All"
    # doesn't give it to you.
    #
    # The Options directive is both complicated and important.  Please see
    # http://httpd.apache.org/docs/2.2/mod/core.html#options
    # for more information.
    #
    Options Indexes FollowSymLinks MultiViews

    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   Options FileInfo AuthConfig Limit
    #
    AllowOverride None

    #
    # Controls who can get stuff from this server.
    #
    Order allow,deny
    Allow from all

</Directory>

Default document root configuration in the Mac OS X Apache server configuration file

 

 

On line 214 the AllowOverride directive is set to None. This instructs Apache to completely ignore .htaccess files. Consequently any re-write rules required for pretty permalinks will not be executed resulting in Error 404 Object not found! errors.

The fix is simple and there are two choices: set the AllowOverride directive to FileInfo or All.

Setting the AllowOverride directive to FileInfo allows the use of mod_rewrite directives in .htaccess files.

    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   Options FileInfo AuthConfig Limit
    #
    AllowOverride FileInfo

</Directory>

Document root AllowOverride directive set to FileInfo in the Mac OS X Apache server configuration file

 

 

Setting the AllowOverride directive to All allows the use of all permissible .htaccess directives in .htaccess files.

    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   Options FileInfo AuthConfig Limit
    #
    AllowOverride All

</Directory>

Document root AllowOverride directive set to All in the Mac OS X Apache server configuration file

 

 

Finally, restart the Apache server to ensure the change takes effect.

For local server environments provided by XAMPP the document root configuration can be found in /Applications/XAMPP/xamppfiles/etc/httpd.conf.

For MAMP it’s /Applications/MAMP/conf/apache/httpd.conf.

When using virtual hosts the AllowOverride directive can be set individually for each virtual host. For instructions on configuring virtual hosts see Configuring Virtual Hosts in XAMPP on Mac OS X and Configuring Virtual Hosts in MAMP on Mac OS X.

About the author

A native Brit exiled in Japan, Steve spends too much of his time struggling with the Japanese language, dreaming of fish & chips and writing the occasional blog post he hopes others will find helpful.

7 responses

7 Comments

  • Unfortunately this does not work for me.
    I still have to put /index.php/ before %postname%.

    How can I fix this to make it work without index.php inbetween?

    • @ekntrtmz

      Sounds like you’re using PATHINFO permalinks which do not use mod_rewrite. Check your permalink structure and remove /index.php from the custom structure. Also, take a look at the .htaccess file in the document root folder of your site. It should contain the following;

      # BEGIN WordPress
      RewriteEngine On
      RewriteBase /
      RewriteRule ^index\.php$ - [L]
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule . /index.php [L]
      # END WordPress
      
      • Thanks a lot. Did not see that my .htaccess was not writable. That’s why it could not work of course.

  • Possible to turn off ScrollJacking / KineticScroll?

    When looking to read a particular section, the kinetic scroll takes it out of the screen.

Steve

Recent Comments

Recent Posts

Archives