Page Not Found on WordPress, Drupal, etc.

If you just set up a site on a new Apache server and no pages will show up beyond the front page and the admin pages, then you may have a problem with how the server rewrites permalinks. 

Modern CMSs like WordPress and Drupal store pages, posts, and such in the database at some pretty ugly URLs by default, so sites will typically employ something called “permalinks” to quietly translate the ugly URL (e.g., www.domain.com/p=?34) into something more user-friendly (e.g., www.domain.com/SomeCoolPage). (Actually, it happens in reverse: i.e., you enter the friendly URL and it’s silently translated by the system into the ugly one.)

If you find that pages aren’t loading on your new Apache server, there are a number of reasons this could happen, but I’m just going to tell you what my issue was when I recently ran up against this problem, since it’s easy to overlook and seems impossible to find a straight-forward explanation anywhere else on the web – especially for the latest versions of Ubuntu/Apache, since the paths have changed from older versions!

First, make sure Apache’s mod_rewrite is enabled to allow it to rewrite/translate the URLs:

sudo a2enmod rewrite

Then restart Apache:

sudo service apache2 reload

…if you get an error upon loading Apache that says something like this:

apache2: Could not reliably determine the server's fully qualified domain name...

…then don’t worry – it’s harmless. However, if you want to make it go away do this (use whatever your favorite text editor is – I like vim):

sudo vim /etc/apache2/conf-available/fqdn.conf

…and enter this into it, then save & close it:

ServerName localhost

Then type:

sudo a2enconf fqdn

Now reloading Apache shouldn’t give you an error anymore. But I digress…

So, now you’ve enabled mod_rewrite, but pages still aren’t loading? This is the part that I got hung up on: you need to “AllowOverride” in apache’s configuration. By default it’s not allowed, so even though it’s enabled in .htaccess, it’s being overridden by Apache’s config.

Type this:

sudo vim /etc/apache2/apache2.conf

…a file will open, and you’ll want to scroll down about 75% of the way until you see something that says “AllowOverride None” – change this to say:

AllowOverride All

You’ll see it listed three times. Make sure all three of them say “All” instead of “None” and save/close the file.

Reboot your server, and your permalinks should now work correctly.

I most recently had this issue on a brand new installation of Ubuntu Server with LAMP running a fresh installation of WordPress running WooCommerce. I started entering products into my site, but every product page would come up as “page not found” when viewed. So then I created a page manually in WordPress and realized it was a bigger problem than just the WooCommerce module, and that’s what ultimately lead me to realize it was this permalink issue. Ironically, I had this same problem years ago on a new Drupal installation, but forgot how I’d fixed it. Now I’ve finally documented the answer for future reference – I hope you found this post quickly enough to not waste as much time as I did figuring it out twice! ;)

Steve