Can a single server be associated with multiple domains?
Yes. This would be done by pointing those domains at your web server via DNS.
If I own the "x.x.x.x" web server, can I make two separate sites on "x.x.x.x/one" and "x.x.x.x/two" and give them two different domains?
This depends on your web server software. You could certainly point both domains to your server, but it would then be up to the server software to distinguish which traffic was intended for which domain.
Some smaller web server projects do not support this kind of feature. However, larger projects often do. In the cases of Apache and Nginx, this support comes via Name-based virtual hosts and server blocks, respectively. Both of these projects also support Server Name Indication (SNI) for TLS (HTTPS) connections as well.
How will it handle internal links in the case (es. x.x.x.x/one/foo/page.html
)?
Typically, you would set the full path to your one
folder as the document root in e.g. your virtual host or server block configuration (i.e. where the "main" domain starts). A page that referenced e.g. example.com/foo/page.html
would then be referencing e.g. x.x.x.x/one/foo/page.html
. If you wanted to use just e.g. example.com/page.html
, you would set your document root to the full path of foo
.
WordPress
WordPress has its own methods of dealing with domains. In your example case, assuming you wanted WordPress to handle both domains, you would:
Specify two domains in DNS.
Create two e.g. virtual hosts (in Apache) corresponding to those domains.
Set each document root to point your WordPress installation.
Configure WordPress to service both those domains.
Otherwise, you would simply point one document root to your WordPress installation (and configure only one domain in WordPress) and point the other document root to your non-WordPress files.
Notes
For the explanation above, I assuming that you have your web server set up at x.x.x.x
and one
and foo
are directories below the default document root you have already set up for the server.
It's worth mentioning that DNS points only to IP addresses (e.g. 1.2.3.4
) or, in the case of CNAME records, whole domains (e.g. example.com
). You cannot point DNS to e.g. http://1.2.3.4/one
.
There are some Domain Providers that may offer web redirects (e.g. to http://1.2.3.4/one
), but these are not part of DNS. How requests for pages would be handled in this situation would (again) entirely depend on your server.
Minimal Apache Virtual Host Examples
ex. Regular Domains
<VirtualHost *:80>
ServerName example1.com
# ServerAlias www.example1.com, *.example1.com
DocumentRoot "/path/to/www/Wordpress_Site"
</VirtualHost>
<VirtualHost *:80>
ServerName example2.com
# ServerAlias www.example2.com, *.example2.com
DocumentRoot "/path/to/www/Non-Wordpress_Site"
</VirtualHost>
ex. Sub-Domains
<VirtualHost *:80>
ServerName sub1.example.com
# ServerAlias www.sub1.example.com, *.sub1.example.com
DocumentRoot "/path/to/www/Wordpress_Site"
</VirtualHost>
<VirtualHost *:80>
ServerName sub2.example.com
# ServerAlias www.sub2.example2.com, *.sub2.example.com
DocumentRoot "/path/to/www/Non-Wordpress_Site"
</VirtualHost>
NamedHosts
in Apache, nginx et al have similar tech (except maybe IIS). For SSL you need SNI support (fairly standard today). Where you will have issues is when scripts, etc. using the local mail service to send emails out (form submissions, password resets, etc). Mail can really only be configured with one name used in theHELO
portion of the transmission, and so for spam purposes all of the domains you host have to allow whatever name you select. Otherwise there will be issues.