Fix WordPress Permalinks(on LAMP)

I had a problem for a while, where when I changed the permalink settings, my whole website would return page not found errors.After a lot of searching through the internet, I managed to find the answer here. Before I explain it, first let me point out that this requires root access to the server, so self-hosted sites will have no problem. Ok, so on to the fix:

  1. SSH into an account with root access on your server.
  2. Run:
     sudo a2enmod rewrite

    to enable the required mod_rewrite module

  3. Change directories to the apache root directory:
     cd /var/www/html
  4. Edit/Create a .htaccess file
     sudo nano .htaccess
  5. Make sure the following exists, or add it:
    # BEGIN WordPress
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    # END WordPress
  6. Give .htaccess the proper permissions with:
    sudo chmod 644 .htaccess
  7. Edit a file with:
     sudo nano /etc/apache2/sites-available/000-default.conf
  8. Add the following to the file(if not present):
    <Directory "/var/www/html">
    AllowOverride All
  9. Edit /etc/apache/apache2.conf
 nano /etc/apache/apache2.conf

10.  Find:

<Directory /var/www/>
 Options Indexes FollowSymLinks
 AllowOverride None
 Require all granted

11 Change AllowOverride None to All:

AllowOverride All

12  Restart apache

 service apache2 restart

One comment

Leave a Reply(Markdown is On)