Search code examples
wordpresshttp-status-code-404httpd.confpermalinks

Updating httpd.conf not working for permalinks


I am unable to set permalinks to end with post names. I receive a 404 error. The closest I got is to set custom permalink to:

/index.php/%postname%

But this causes 'index.php' to show up in the URL. I also updated my httpd.conf to set the root dir to:

AllowOverride All

But it still does not work. My wordpress is hosted on AWS EC2 linux AMI.


Solution

  • Activate the mod_rewrite module with

    sudo a2enmod rewrite
    

    and restart the apache

    sudo service apache2 restart
    

    To use mod_rewrite from within .htaccess files (which is a very common use case), edit the default VirtualHost with

    sudo nano /etc/apache2/sites-available/000-default.conf
    

    Below “DocumentRoot /var/www/html” add the following lines:

    <Directory “/var/www/html”>
    AllowOverride All
    </Directory>
    

    Restart the server again:

    sudo service apache2 restart
    

    EDIT:

    Found my htaccess file was missing. So followed the steps listed here :

    https://wordpress.org/support/article/using-permalinks/#wheres-my-htaccess-file

    • Created htaccess in wp root which, on my server, was /var/www/html.
    • Added the required rewrite rules provided in the link above.
    • Set chmod on htaccess to 775
    • Set chown on htaccess to apache:apache
    • Restarted httpd service

    Postname permalink now works!