1

I have taken a copy of my Wordpress website and set up a subdomain, and virtual host (/var/www/subdomain/) on the existing websites server. After moving the copy of the website I am getting a 404 error on all pages except the Home Page and WP Admin area.

Apache Conf file below;

<VirtualHost *:80>
ServerName subdomain.example.com
ServerAlias subdomain.example.com
DocumentRoot /var/www/subdomain
RewriteEngine on
RewriteCond %{SERVER_NAME} =subdomain.example.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

Edited

Also below is the SSL Cert apache conf

<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName subdomain.example.com
ServerAlias subdomain.example.com
DocumentRoot /var/www/subdomain

SSLCertificateFile /certfile/directory/
SSLCertificateKeyFile /certfile/directory/
Include /certfile/directory/
</VirtualHost>
</IfModule>

I have ensured the htaccess file is present, site url and home url are updated and resaved the permalinks, but the 404 error is still happening. I have also tried disabling plugins to make sure nothing was clashing

HTACCESS File below;

# 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

The existing Wordpress website on the server (/var/www/html/) is working fine and has no errors.

Any suggestions on things I might have missed / not set up correctly would be greatly appreciated.

Thank you

2
  • You've only posted <VirtualHost *:80> which just redirects to HTTPS (aside: you don't need mod_rewrite for this), so you must also have <VirtualHost *:443> with a SSL cert that actually handles the request? Also bear in mind that WP stores the hostname in the DB, so it's not simply a case of moving the site files to a new host unfortunately.
    – MrWhite
    Mar 9, 2022 at 9:35
  • Thanks for replying, I have included the conf files which handles ssl, my mistake forgot to include that one. Yes - I have updated the hostname within the DB, that was one of the things I initially did / checked after moving the website.
    – JWilliam
    Mar 9, 2022 at 10:07

1 Answer 1

2

You don't appear to have allowed .htaccess overrides in the <VirtualHost *:443> container, so .htaccess is effectively disabled. Without .htaccess you'll naturally get 404s for anything other than the homepage if you are using "pretty" permalinks. (.htaccess is not required for requests to the homepage, since index.php is served by mod_dir which is no doubt configured elsewhere in the main server config.)

You need something like this inside the <VirtualHost *:443> container:

<Directory /var/www/subdomain>
    Require all granted

    # Enable .htaccess overrides
    AllowOverride All
</Directory>

You don't appear to be allowing access (ie. Require all granted) in the config you've posted so you are presumably handling this outside of the vHost? But make sure you are not enabling access to too much.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.