VirtualHost for subdomain also re-routes traffic to host domain
I ended up finding a solution, and to anyone in the future with the same problem, this is what I did:
NameVirtualHost *:80
<VirtualHost *:80>
ServerName www.example.com
ServerAlias example.com
DocumentRoot "C:/xampp/htdocs/"
</VirtualHost>
<VirtualHost *:80>
ServerName sub.example.com
DocumentRoot "C:/xampp/htdocs/sub"
</VirtualHost>
I assume that basically for the VirtualHost to differentiate between sub.example.com
and example.com
then a VirtualHost first must be defined for example.com
before any subdomains can be configured
How to Alias a Page to a Sub-Domain
I found the answer in this thread.
To summarize, you need to proxy the request with nginx:
# abc.example.com
server {
listen 80;
server_name .example.com;
location / {
proxy_pass http://127.0.0.1/abc$request_uri;
proxy_set_header Host example.com;
}
}
The just setup an A record pointing at your server's IP.
Rewrite one Domain to Another without changing Address bar
Link to previous post discussing differences between redirect, rewrite, and virtual hosts.
What it sounds like you're trying to do can be accomplished by setting up your new content in the new location (using a new name for testing) and then configure a rewrite or redirect, depending on how you want the client's browser to treat it (also some SEO implications), on the old site to load the new site's content. Normally, I've done this load balancers in front of the servers, but it can be accomplished with mod_rewrite as well.
One of the concerns I would have is how dynamic your content is. If "switching" sites from old to new will disrupt your customers, then you would definitely want to push them off the old servers, either by redirect or rewrite, as soon as the new name comes online.
Related Topics
How to Delete an Object's Property in PHP
Change Timezone in Lumen or Laravel 5
How to Check If Curl Is Enabled or Disabled
PHP Header(Location: ...): Force Url Change in Address Bar
Resize/Crop/Pad a Picture to a Fixed Size
How to Copy a File from One Directory to Another Using PHP
Is PHP's Count() Function O(1) or O(N) for Arrays
PHP Get Highest Value from Array
Error While Sending Query Packet
PHP Curl Curlopt_Ssl_Verifypeer Ignored
Why Can't PHP Create a Directory with 777 Permissions
PHP Add Elements to Multidimensional Array with Array_Push
Email from PHP Has Broken Subject Header Encoding
How to Get System Environment Variables into PHP While Running Cli & Apache2Handler
In PHP, Can You Instantiate an Object and Call a Method on the Same Line