Question

Homepage Works but Pages/Posts shows 404 error (apache)

I’ve successfully migrated to Digital Ocean from Cloudways (was utilizing DO as well).

However, except the homepage every other page shows 404 error. (reference: https://stackoverflow.com/questions/5182534/wordpress-is-giving-me-404-page-not-found-for-all-pages-except-the-homepage)

I’ve looked online and found a couple of solutions:

  1. Change permalinks to default and then back again to your target URL pattern - Didn’t work.
  2. Check your .htaccess file and disable it to see whether that’s what causing the issue - Checked, nothing wrong with that and also WordPress is able to generate a new .htaccess file - so it has the required persmissions
  3. Check your Apache config and ensure that it includes:

<Directory> Options Indexes FollowSymLinks AllowOverride All Require all granted </Directory>

where AllowOverride should be set to All…

I’ve checked that as well - both vHost file for the domain and the apache2.conf file contains that piece of code.

Am I missing something else? Is there any other way to resolve the error?

Additional Info: When I change my site permalinks to default i.e domain.com/?123 (the defaul URL structure of WordPress) - it works fine. That means, the site has been restored perfectly.

P.S: Installed WordPress manually for this domain and I have virtual hosts configured in a 1-click WordPress ubuntu 18.04 droplet.

Show comments

Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Accepted Answer

Got a response from the official DO support:

Replaced my original .htacess content (generated by WordPress) with this and it worked.

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

Bobby Iliev
Site Moderator
Site Moderator badge
October 18, 2021

Hello,

Just came across this question and wanted to mention one more thing to what has already been said. You would also need to make sure that you have Mod Rewrite enabled in order for the .htaccess rules to work:

sudo a2enmod rewrite

After enabling the module, run an Apache config test:

sudo apache2ctl -t

And if you get Syntax OK then make sure to restart Apache:

sudo systemctl restart apache2

Regards, Bobby

Thanks. it worked for me.

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Featured on Community

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more