How to Detect an Incoming Request (With PHP Script) from a Cname Subdomain

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



Leave a reply



Submit