Reputation: 129
I have one single Wordpress application on domain www.mywpsite.com.
I have static pages:
a. www.mywpsite.com/subsite
b. www.mywpsite.com/subsite/child1
c. www.mywpsite.com/subsite/child2
and need that content to be respectively addressed using a subdomain like this:
a. subsite.mywpsite.com
b. subsite.mywpsite.com/child1
c. subsite.mywpsite.com/child2
Note that there is no physical structure for the subdomain, it is just a way of aliasing, and there is only one Wordpress installation under one document root. Also, I have a few pages and just one subdomain to work with, so a 'case by case' solution is valid.
Eventually I will also use the same subdomain for some dynamic content:
d. www.mywpsite.com/category/subsitenews => subsite.mywpsite.com/news
Finally, if possible, I need that the url retained in the address bar is the one using the subdomain, I mean:
How can I do this?
I think I must use .htaccess but I have no idea how it works. I'm not sure if other questions I have found have to do with my problem.
redirect subdomain and retain url structure
.htaccess redirect ~ [fake-subdomain.domain.com/*] to [domain.com/*]
Thank you very much.
Upvotes: 2
Views: 669
Reputation: 143846
If the subdomain's aren't on the same server and under the same document root as the main domain, then you'll need to use a reverse proxy, or the P
flag using mod_rewrite. You can try adding these rules to the htaccess file in your document root, preferably above any rules that may already be there:
RewriteEngine
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?([^/]+)/([^/]+)/?$ http://$1.mywpsite.com/$2 [L,P]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?([^/]+)/?$ http://$1.mywpsite.com/ [L,P]
The problem here is that dynamic content, ones that wordpress dynamically generates, will also be sent to the subdomains. There is no way to tell on the htaccess level what's valid dynamic content and what isn't. In order to check for that, you'll need to do it from within the wordpress CMS, probably some way of doing that but it'll require custom code or at least a plugin and possible customizing the plugin.
Upvotes: 1