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

Steve April 18 Local Server , , , , with 7 and 0
Home/Local Server/Fixing WordPress “404 Object Not Found” Errors on a Mac OS X Local Server Environment

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

  • ekntrtmz
    on July 3rd, 2017 at 22:05
    Reply

    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?

    • Author
      Steve
      on July 4th, 2017 at 10:08
      Reply

      @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
      
      • ekntrtmz
        on July 5th, 2017 at 14:22
        Reply

        Thanks a lot. Did not see that my .htaccess was not writable. That’s why it could not work of course.

  • Manish
    on October 23rd, 2014 at 20:29
    Reply

    Possible to turn off ScrollJacking / KineticScroll?

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

  • Manish
    on October 23rd, 2014 at 20:27
    Reply

    Thank you for writing this!

    @everyone Remember to restart Apache after the change.

  • Josh
    on July 28th, 2012 at 01:55
    Reply

    This is exactly what I’ve been looking for, and was a huge help! Thanks a lot.

    • Author
      Steve
      on July 28th, 2012 at 06:22
      Reply

      Glad you found it useful Josh.

      Regards, Steve.

Add comment

©Tech Otaku 2009 - 2017