Using wildcard subdomain on specific directory

2019-05-23 10:12发布

I am setting up an existing wordpress install to use multisite. I have successfully set up the network and since it was an existing install it uses subdomains (which I wanted anyways).

I have created a new site/subdomain on my network so it would look something like this example.domain.com

The issue I am running into is getting wildcard subdomains setup on my hosting provider BlueHost.

I am hosting multiple domains so when I setup a wildcard it always points to the root or original ip address.

I need it to point to a specific directory of the root so it uses the correct wordpress install. root/specific-directory

Is there a way to achieve this? I am not too familiar with a and cname issues. If there is a way to achieve it by writing in the htaccess that would be okay too.

2条回答
虎瘦雄心在
2楼-- · 2019-05-23 10:23

I am hosting multiple domains so when I setup a wildcard it always points to the root

I'm assuming you meant that you get the same content for example.domain.com as if you were visiting www.domain.com. This can surely be handled through htaccess rewrite rules.

If a sub-domain named subsite was to be served out of ${DOCUMENT_ROOT}/subsite directory, you would add the following rules to your .htaccess placed at your web root / directory:

RewriteEngine on
RewriteBase /

RewriteCond %{HTTP_HOST} ^subsite\.domain\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/subsite [NC]
RewriteRule ^(.*)$ /subsite/$1 [L]

If there are several mutisite subdomains that need redirection, use the following dynamic rules instead:

RewriteEngine on
RewriteBase /

RewriteCond %{HTTP_HOST} ^(?!www\.)([^.]+)\.domain\.com$ [NC]
RewriteCond %{REQUEST_URI}::%1 !^/([^/]+).*?::\1
RewriteRule ^(.*)$ /%1/$1 [L]

You would also need to add ServerAlias *.domain.com to your <VirtualHost> configuration in Apache's httpd.conf file.


It seems BlueHost doesn't take up any requests to modify httpd.conf directly for you. But, they do provide a way to setup a wildcard subdomain from their Control Panel.

Take a look at How to Set Up a WordPress MultiSite in Bluehost. The last section outlines the process with screen shots. You also need to enable theme per site for your subdomains.

Wildcard Subdomain

查看更多
欢心
3楼-- · 2019-05-23 10:25

1- You can add your subdomain as an addon domain and it can have a separate subdirectory as you want.
2- Another way to achieve this is using another host for subdomians. On the second host you set up your subdomains and point your subdomains from your main host to subdomains on the secondary host.

查看更多
登录 后发表回答