How to fix the Not Found/404 page after using WordPress Permalinks on a server running Apache

So I recently bought a server for a year at Ramnode, just because I create a bunch of websites all the time and I got really tired of creating accounts on 000webhost.

In their defense, 000webhost offers an okay product, but unfortunately their generosity is often abused leading to their domains being blacklisted for things done on their servers.

This is sadly what happened to my podcast’s site, which is now banned from Facebook:

banned from Facebook

 

Anyway, back to the point.  After migrating my WordPress site, I noticed that there were issues with my custom URLs that were leading to the 404 page.  It took my a couple hours, but I finally figured it out.

Step 1 – Super important!

The absolute first step you have to do is launch rewrite in Apache.  This was the thing that I was missing.  To do this, SSH into your server and enter:

sudo a2enmod rewrite

Then reset apache by entering:
/etc/init.d/apache2 restart

Step 2 – AllowOverride All

Since my server hosts multiple domains, this step might vary, but in Apache there is a file called httpd.conf in /etc/apache2/ which does a lot of magical jibberish.  If you have multiple domains, this magical jibberish file is actually located in /etc/apache2/sites-available/___yourdomain___.

You’ll know you’ve found the right file when the first line in that file is:

<VirtualHost *:80>

In side that file, find every instance of “AllowOverride” and turn it into “AllowOverride All”.

Save the file, then reset Apache again by entering:
/etc/init.d/apache2 restart

 Step 3 – Optional – Change your permissions of .htaccess

So you may or may not have to do this step.  First go to Settings > Permalinks.  Select any link format that isn’t the default then save.  If it says “If your .htaccess file were writable, we could do this automatically, but it isn’t so these are the mod_rewrite rules you should have in your .htaccess file”, you’ll have to edit the file permissions of the .htaccess file.

The easiest way is to FTP into your directory, right click on .htaccess and change the number from whatever to “777”.  Then, go back into that permalinks page, select your custom field and click okay.  It will edit (or generate if you don’t already have one) a .htaccess file.

After that you MUST change your permissions back to “644”.  I cannot stress that enough.  YOU MUST CHANGE PERMISSIONS BACK TO 644 OR YOUR WORDPRESS INSTALL WILL HAVE A SECURITY HOLE.

If you need to do it using the command line, I’m sure you can easily google a way to do that.

That’s it!  Enjoy your new custom links!

Thanks a lot to Digital Ocean for providing me with Step 1 and everyone on the WordPress forums for the remaining steps.

5 Comments

  1. This was great information. Spelled it out better than any other resource I was able to find on the subject. I used it when running into issues with my DigitalOcean migration.

    Thanks!
    Phil

    Reply

  2. I can’t quite explain the relief when I came across your post. I had spent at least 2 hours trying all manner of things.

    The question I have is whether leaving the “AllowOverride” to “All” leaves a security hole or should I change them all back to “None” after making the change?

    Reply

Leave a Reply