Wordpress 404 on Subdomain

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

Topic subdomains apache htaccess 404-error Wordpress

Category Web


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.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.