0

Ok so i have my mu setup with subdomains and need a subdomian to point to a different path. My issue is when i add the vhost file it loads before wordpress and loads it path for everything that does not have an assigned path in my vhosts config. But if i load after wordpress domain install then it trys to create a site for the subdomain entered.

What i need is this:
sub2.mydomain.com - points to /path/to/sub/directory
*.mydomain.com - points to /path/to/wordpress/install

UPDATE:
I am using a domain mapping plugin which i think is causing my issue. All sub sites load fine but when i load a mapped domain to a sub site it does not work.

I can not add my mapped domain each time to my vhost config since i plan on allowing others to map domains

8
  • This is a server setup question, not a WordPress question. I vote we close and migrate to ServerFault or SuperUser. Commented Jun 1, 2011 at 17:46
  • Yes and no. As wordpress has a feature to ignore subdomains codex.wordpress.org/WPMU_Ignore_Some_Subdomains And was curious if anyone new how to use the vhost feature. I have already asked over there and i get comments saying i should come here. SO i am here now Commented Jun 1, 2011 at 18:24
  • That is not a WordPress feature. That is a codex page informing you that there are server configurations you may wish to use that can give you distinctly NON-WordPress functionality that doesn't conflict with your WordPress installation. Commented Jun 2, 2011 at 14:10
  • Also, I'm a little disappointed in the laziness of the people at whichever site you came from with this question. It's a very simple question of using two vhost declarations and making sure that more specific hosts (e.g. sub2.domain.com) come before less specific vhosts (e.g. *.domain.com). If we migrate this question, I'll answer it myself. Commented Jun 2, 2011 at 14:13
  • Laziness?? wow come on dude no need to be rude. I have tried using vhosts i have tried putting my subdomain that i want to load a different path before the WordPress domains and no luck. I am posting here because i was not sure if the vhost config is a normal config or if it was special for WordPress. The codex page is a little less on the info. And if you think it should be moved then flag it for that. Commented Jun 2, 2011 at 21:25

3 Answers 3

3

Basically, it turns out you need two dedicated IP addresses, or a third vhost.

IP Address

You could use two IP addresses and do something like this in your apache configuration:

#IP address for WP
NameVirtualHost 12.34.56.78:80
#For everything else
NameVirtualHost *:80

Then, make sure the VirtualHost for WordPress is declared thus:

<VirtualHost 12.34.56.78:80>

and all other VirtualHost blocks declared before WordPress use the other one:

<VirtualHost *:80>

That should work. I haven't tested this AT ALL, so it may not work. Also, I'm not sure using the asterisk in the second NameVirtualHost line will work; again: untested.

CNAME

Assuming your domain mapping plugin allows for this, use the 'cname' method of routing mapped domains instead of the 'IP' method. Use something like 'map.domain.com' and have mapped domains point a cname to that (this will prevent them from using the root of their domain, but they should be able to 301 redirect example.com to www.example.com)

Add another VirtualHost entry for 'map.domain.com' as the first vhost entry, mirroring the main vhost entry for the domain, specifically: the document root.

Again, this is also untested.

SUBDOMAIN CONFIGURATION (OLD ANSWER)

I'll use my own site's virtual host file as an example. This is all in one file:

# Virtual host for the subdomain first
<VirtualHost *:80>
    ServerAdmin [email protected]
    ServerName drupal.johnpbloch.com
    # Note that the document root and all other paths are different from the domain's primary virtual host below.
    DocumentRoot /path/to/subdomain/directory/htdocs/
    ErrorLog /path/to/subdomain/directory/logs/error.log
    CustomLog /path/to/subdomain/directory/logs/access.log combined
    <Directory /path/to/subdomain/directory/htdocs/>
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>
# Virtual host for the main site next
<VirtualHost *:80>
    ServerAdmin [email protected]
    ServerName johnpbloch.com
    ServerAlias www.johnpbloch.com
    ServerAlias *.johnpbloch.com
    DocumentRoot /path/to/main/site/directory/htdocs/
    ErrorLog /path/to/main/site/directory/logs/error.log
    CustomLog /path/to/main/site/directory/logs/access.log combined
    <Directory /path/to/main/site/directory/htdocs/>
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

That doesn't have to all be in one file; the important part is that Apache loads the more specific virtual host first. That means any virtual hosts with no wildcards in any ServerAlias values must be loaded before any virtual hosts with those wildcard values.

There is no value, no setting, nothing you could possible do with, in or around WordPress that could possibly solve your problem. By the time the request has reached WordPress, it's too late. Apache has already loaded the virtual hosts, already resolved the hosts, and will always route the traffic the way it does. If the traffic is getting to WordPress when it shouldn't be that is a server configuration issue. Not WordPress.

12
  • And, as always, make sure you restart apache after making any changes to the configuration. Commented Jun 3, 2011 at 0:07
  • So i did the above which i have done before now it is a wordpress problem see updated question Commented Jun 3, 2011 at 7:03
  • So i have tried this over and over still nothing. I know that this is only an issue with using a domain mapping plugin as soon as i load sub1.mydomain.com it loads the default directory. But as soon as i remove the entry in vhost everything works fine. Commented Jun 7, 2011 at 7:11
  • So here's what's happening. Any random domain routing to your server without a vhost declared will default to the first vhost defined in Apache. Period. Which means, for them to go to your WP install, it has to be first. But you have to set the subdomain first if you want to serve it out of a different directory tree. That's a real catch 22 there. I'll see if I can find a solution... Commented Jun 7, 2011 at 14:30
  • Alright john. I have tried adding the .htaccess code but no luck. I just need WordPress to ignore one sub-domain thats it. Like i mentioned above when i use your setup it works but all my mapped domains go to the first listed vhost as it is considered default. But if i go after wp vhost then mapped domains go to there proper location but then i have problems with one sub-domain going to the WordPress installation and asking me to register since it is not in use. The directory for wp is /home/username/public_html/wp and the path for the subdomain is /home/username/public_html/subdomain , Thanks Commented Jun 7, 2011 at 17:01
0

I ran into this on my server as well, and I can guarantee you that John's answer is correct. To prove it, here is the vhost section from my own Apache configuration file:

<VirtualHost *:80>
    ServerName prosepainting.com
    ServerAlias www.prosepainting.com *.prosepainting.com
    DocumentRoot /var/www/html/eamann
</VirtualHost>
<VirtualHost *:80>
    ServerName mindsharestrategy.com
    ServerAlias www.mindsharestrategy.com *.mindsharestrategy.com
    DocumentRoot /var/www/html/eamann
</VirtualHost>
<VirtualHost *:80>
    ServerName groundedchristianity.com
    ServerAlias www.groundedchristianity.com *.groundedchristianity.com
    DocumentRoot /var/www/html/eamann
</VirtualHost>
<VirtualHost *:80>
    ServerName prose.eamann.com
    DocumentRoot /var/www/html/eamann
</VirtualHost>
<VirtualHost *:80>
    ServerName business.eamann.com
    DocumentRoot /var/www/html/eamann
</VirtualHost>
<VirtualHost *:80>
    ServerName git.eamann.com
    DocumentRoot /home/git/repositories
</VirtualHost>
<VirtualHost *:80>
    ServerName eamann.com
    ServerAlias www.eamann.com *.eamann.com
    DocumentRoot /var/www/html/eamann
</VirtualHost>
<VirtualHost *:80>
    DocumentRoot /var/www/html
</VirtualHost>

I have it set up this way because I will selectively turn each mapped domain on and off for testing. But all of the sites in my WordPress installation are subdomains of eamann.com and get mapped to the right location by the *.eamann.com declaration. To set up the mapped domains, I needed to add them as well.

To make things simpler, this configuration would do the exact same thing:

<VirtualHost *:80>
    ServerName git.eamann.com
    DocumentRoot /home/git/repositories
</VirtualHost>
<VirtualHost *:80>
    ServerName eamann.com
    ServerAlias www.prosepainting.com *.prosepainting.com www.mindsharestrategy.com *.mindsharestrategy.com www.groundedchristianity.com *.groundedchristianity.com www.eamann.com *.eamann.com
    DocumentRoot /var/www/html/eamann
</VirtualHost>
<VirtualHost *:80>
    DocumentRoot /var/www/html
</VirtualHost>

My git.eamann.com domain is directed to one location (my Git repository folder) but WordPress will still see all other subdomains and my mapped domains will point to WordPress as well.

0

Since my domain mapping plugin does not do cname (wpmudev domain mapping) i could not use the cname suggestion. As for the ip address this is untested as i do not want to add more to my hosting bill at this time maybe in the feature ill give it a shot. ordering the vhosts and assigning alias works but like i said in a previous comment i plan on allowing other users to map a domain name and that means i would have to add it manually every time one was registered.

My solution is this:
I created a wp site with a sub-domain of my choice and then created a sym link in the wp root folder (i know that i can access from any site but not many people will not that) so when i type in subdomain1.mydomain.com/analytics it will load the analytics same goes for my issue tracking script. By creating the site i can create a page that shows a list of services that can be accessed.

Thanks John P Bloch for your help i know this was not a WordPress issue completely but since it was my domain mapping plugin that to me made it enough as well thank you EAMann this would work but like i said above i would need to create a s-alias every-time.

2
  • Considering the free domain mapping plugin does everything the wpmudev plugin does and more, I'd say you got ripped off. I'm glad you found a hack to work around your server's inadequate configuration and your mapping plugin's dearth of features that exist elsewhere. I'd also like to point out that I answered your question, not because I think it belongs here, but to prove that it doesn't. Not a single suggested solution, including the one you used, had anything to do with WordPress, but rather with server configurations. Commented Jun 8, 2011 at 12:05
  • the one thing that the wpmudev does is allow for paid use only. I have seen the other one and may use it. I have used more of the other wpmudev plugins that are not available for free so i did not get ripped off i use some of there other plugins. I still beleave that part of it is wordpress i am not the only one who has problems with existing sub domains when using a domain mapping plugin. I do not want to add a server-alias everytime a new domain is mapped. Commented Jun 8, 2011 at 17:12

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.