You shouldn’t need to add anything to .htaccess
. Assuming your subdomain points to the same place on the filesystem as the main domain then you need to configure WP to accept requests to both hostnames (to prevent a canonical redirect – which is what I assume you were experiencing?).
In other words, instead of hardcoding the domain name in WordPress (WP_SITEURL
and WP_HOME
), you need to make this dynamic based on the requested hostname.
For example, in wp-config.php
set the following:
define('WP_SITEURL','https://'.$_SERVER['HTTP_HOST']);
define('WP_HOME','https://'.$_SERVER['HTTP_HOST']);
RewriteCond %{HTTP_HOST} ^(.*)\.example\.com$ RewriteRule ^(.*)$ http://example.com [P]
This is attempting to “proxy” the request from the subdomain to your main domain – using your server as a reverse proxy. This requires access to your server config to configure (properly).