Host homepage on a different server than the rest of site [duplicate] - dns

This question already has answers here:
possible to resolve DNS based on URL path
(3 answers)
Closed 5 years ago.
Is it possible to host one page of a website (example.com/index.html) on a different server than the remainder of the site (example.com/blog/ and etc.)? Are there ways to manage this through DNS settings? An .htaccess file?
Thanks!

Short answer is, not really. A DNS entry maps a hostname (example.com) to an IP address. The path part of the url (/index.html) is not part of the hostname, and is only contained inside the http headers.
The general practice for this kind of situation is to use a proxy or load balancer which will send requests to different servers depending on the request path.
If it really needs to go to two different places without a central load balancer, then you probably need a unique subdomain for each site.

Related

how can my flask app create a subdomain automatically for my user? [duplicate]

This question already has answers here:
How to create dynamic subdomains in a Flask application
(2 answers)
Closed 3 years ago.
I have built a flask application that will be used by restaurants, I want to know how I can make the app give each restaurant a subdomain and own database when they register for an account on our landing page.
This question sounds like it is more about the Domain Name System than Flask.
You're saying that your server will start running, and then days or weeks later a new client will register with some new restaurant_name, e.g. "spicytacos". You would like to create a new spicytacos.example.com FQDN in the Domain Name System, with A or AAAA record pointing at your webserver. Then your flask app will be able to recognize the restaurant's name in request.args and respond appropriately.
If you're running the primary nameserver of example.com with BIND9 or similar, then it's just a matter of re-writing the zone config file and sending a HUP signal.
If you prefer to let some other firm handle nameservice details, then probably a * wildcard record is your best bet. It should be a CNAME or address record pointing to your server.
A middle path would be to use a DDNS (dynamic DNS) service, perhaps from afraid.org or No-IP. That is another way of binding a FQDN to an address, which gives you a little more control.
Please refer to How to create dynamic subdomains in a Flask application to see how #app.before_request can parse out novel hostnames during request routing.

IIS 7 IP address forwarding

I want to move some websites from server 1 to server 2.
My clients have A records pointing to the IP address of server 1. Without updating their DNS records, how can I automatically forward request for those domains from server 1 to server 2?
Thanks
Graham
This image is from an article regarding Exchange, but the IIS settings are relevant.
You can redirect at the HTTP level by specifying a URL redirect in IIS's HTTP Redirect settings:-
However, for this approach to work you will need a new domain for your sites. e.g. if the A record resolves www.example.com to Server 1 you will need to redirect to another URL (e.g. www.example.edu) that already resolves to Server 2.
Another option is to setup a reverse proxy using IIS on Server 1:
Today there was a question in the IIS.net Forums asking how to expose two different Internet sites from another site making them look like if they were subdirectories in the main site.
So for example the goal was to have a site: www.site.com expose a www.site.com/company1 and a www.site.com/company2 and have the content from www.company1.com served for the first one and www.company2.com served in the second one
So slightly different requirements (the article only wants a subdirectory rather than the whole site), but the same concept will apply.

Serving pretty much the same site to different domains with express.js [duplicate]

This question already has an answer here:
Multiple domains, single node (express) app
(1 answer)
Closed 8 years ago.
I'm trying to build an app that generates individual websites.
The idea is for the owner to register his domain, tell it to my platform, point it to my amazon server (still not sure how too).
Then on my express.js server I serve content based on the domain the request is coming from.
You can get the requested hostname from the headers from a field called 'host'. For a node http.ServerRequest, it's available at request.headers.host. For an express app, it can be accessed from req.get('host'). With the hostname, you can route calls from different hostnames to different responses.
http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.23

How to display content from another domain by editing CNAME records?

I have a site that lets people have their own e-stores, for ex- mysite.com/clientname
What I want is, if somebody opens store.clientname.com or clientname.com/store, the content is pulled from mysite.com/clientname. [ So that their users feel that they are browsing on their site ]
I know this is possible because site'e like tumblr let you do that by changing a CNAME entry for your domain to their IP address.
I do have a dedicated IP address.
Also, can this be done by editing the .htaccess file at clientname.com, and if yes, which method is better/easy?
You'll want to solve the problem in a completely different way for http://store.clientname.com/ versus http://clientname.com/store.
In the first case, you can serve the web site as a virtual host. Just set up a virtual host called store.clientname.com and set its DocumentRoot to be the existing directory that contains the files for http://mysite.com/clientname. If you have other web server configuration directives that apply to http://mysite.com/clientname then you'll also want to apply those in the virtual host. Finally, the client can set up a CNAME record in DNS for store.clientname.com pointing to your web server.
If you are using Apache, you can also use a default virtual host and mod_rewrite to dynamically translate URLs of the form http://store.{whatever}/ to http://mysite.com/{whatever}/. However, this won't work if you are using HTTPS.
In the second case, you don't want to serve the web site at http://clientname.com/ because the client presumably is already hosting that and presumably http://clientname.com/otherstuff has to continue working and come from their server. So the second case is easier for you because all the work has to be done on the client's web server. But it's simple: they will just have to configure their web server to proxy http://clientname.com/store to http://mysite.com/clientname.

Using DNS to redirect to another URL with a path [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 3 years ago.
Improve this question
I'm trying to redirect a domain to another via DNS.
I know that using IN CNAME it's posible.
www.proof.com IN CNAME www.proof-two.com.
What i need is a redirection with a path. When someone types www.proof.com, it should take them to to www.proof-two.com/path/index.htm
I know it can be done using Web Server facilities, but I need DNS redirection.
Is this possible?
No, what you ask is not possible. DNS is name resolution system and knows nothing about HTTP.
if you use AWS, a redirect like
mail.foo.com --> mail.google.com/a/foo.com
can be setup as follows:
in s3, create an empty bucket "mail.foo.com"
under Properties -> Static Website Hosting, set "redirect all requests to: mail.google.com/a/foo.com"
in route53, create an A record "mail.foo.com"
enable "alias", and set alias target to the "mail.foo.com" bucket
not a pure DNS solution, but it works ;)
But be aware of, the redirect skips all the URL parameters e.g.: ...?param1=value1&param2=value2
I realize this is an old thread but FWIW, incase someone else is looking for a way to do this.
While dns does not understand the path portion of the url, it will understand subdomains, so instead of:
www.proof.com IN CNAME www.proof-two.com/path/index.htm
You could use:
www.proof.com IN CNAME proof.proof-two.com
then go to wherever you host proof-two.com and set it to point proof.proof-two.com to www.proof-two.com/path/index.htm.
~ there's always more than one way to skin a cat
Some providers allow this but there are no "pure" DNS solutions since DNS doesn't know anything about the protocol you're using and redirects are a feature from HTTP.
For OVH, see : https://docs.ovh.com/gb/en/domains/redirect-domain-name/
You will have to use the control panel to add your redirection. It will update your DNS zone accordingly.
Let's consider you created a redirection from foo.bar.com to foo2.bar.com/path. OVH keeps the url paths and parameters. So if you try to access foo.bar.com/hello?foo=bar, you'll be redirected to foo2.bar.com/path/hello?foo=bar.
I have a personal project that might help you in solving this issue.
It's an open source redirect solution that allows you to redirect your domain just changing your DNS settings. Link of the project: https://redirect.center/.
To redirect www.proof.com to www.proof-two.com keeping the URL parameters, just set your www DNS entry on proof.com:
www.proof.com IN CNAME www.proof-two.com.opts-uri.redirect.center.
Really it's easy with redirect.center
If you want create a CNAME as :
www.proof.com IN CNAME www.proof-two.com/path/index.htm
using redirect.center your CNAME look as canonical mode as:
www.proof.com IN CNAME www.proof-two.com.opts-slash.path.opts-slash.index.htm.redirect.center.
Now if you want redirect to https website you can add this option:
www.proof.com IN CNAME www.proof-two.com.opts-slash.path.opts-slash.index.htm.opts-https.redirect.center.
Now you can create a CNAME with the canonical mode with slash in your destiny page.
To answer the original question, no, what you want is not possible using only DNS (like everyone has stated). In addition to everything mentioned already, another option is to use a URL redirection service. These types of services can enable you to configure many different types of URL redirects depending on your needs. For example:
Forward a domain apex to a www. subdomain or vice versa
Forward a collection of domain names to a single destination (useful for forwarding domain misspellings, old company names, etc.)
Forward specific domain names to deeply linked pages (like what the OP wants)
A service that does this is EasyRedir. Full disclosure: I developed EasyRedir. There are certainly other options out there though, so I encourage you to have a look around.
DNS won't redirect the path portion of a URL, so that won't be possible.
Adding
www.proof.com IN CNAME www.proof-two.com
will direct access to www.proof.com to www.proof-two.com, where you will need to use web server config to direct users to the appropriate page.
A related work concluded all the below:
Problem:
http://a.com/p1/p2.html should go to http://B.com/p1/p2.html
today, but later when configured manually/automatically, the same
http://a.com/p1/p2.html should go to http://C.com/p1/p2.html
Answers:
DNS - converts name to IP address
Though it can do a lot of redirects, always output is IP address
DNS does not understand the path or protocol part of URL, understands domain part only, that is, a.com only is converted to IP address, so when you hit http://a.com/p1/p2.html may be converted to http://152.132.121.11/p1/p2.html
if you configure wrong in DNS, then you will get 152.132.121.11 (not http://152.132.121.11/p1/p2.html), so you would get some 400s error (400, 403, etc.)
Redirection - this is http://a.com/p1/p2.html can be converted to http://b.com/p1/p2.html
All the methods like GET, POST can work, with if any headers and body, but there is a web server is involved, it could be point of failure, so scalability and availability will be key
If you are on AWS, Route 53 -> API Gateway is possible though custom domains, internally using the Cloud front
It is possible with Amazon Certification Manager, AWS Gateway custom domains & Route53, note the us-east-1 restriction on ACM
Hope that helps someone
I will suppose you have this scenario: You have a unique webserver hosting various websites, each one is supposed to be presented by a separated domain:
http://example.com/customer1/website/page1.html
http://example.com/customer2/website/page2.html
so, the page1.html should be served by www.customer1.com and so on.
create a subdomain inside the example.com dns server (your webserver):
customer1.example.com
in your apache virtual server settings, map the subdomain to the directory that contain the web site for your customer #1, like this:
<VirtualHost *:80>
SetEnv PAGE_ID "customer1"
ServerName customer1.example.com
ServerAlias www.customer1.com
DocumentRoot /your/local/path/webserver/customer1
</VirtualHost>
please note the value for "ServerAlias", it is important for the next step-
at this point, you should be able to navigate to your customer1 website by browsing to:
customer1.example.com
In the DNS settings for customer1.com you must make a CNAME record:
CNAME=www
LOCATION=customer1.example.com
Now, you're enabled to use: www.customer1.com.
My solution to this problem was pretty simple and straight forward. All you need is an IIS server running inside the domain.
Setup CNAME in DNS to point to the IIS server, using host names in IIS to resolve several sites on a single IIS server. I'm using the same IIS server to farm out a few sub domains to external sites.
Then in IIS setup setup redirection for that site to go to your offsite site/path, in my case it was our hosted catalog that I wanted catalog.ourdomain.com to go to. From here all the tweaking is done in IIS. Be sure to enable anonymous authentication so traffic will not be blocked.
While as almost everyone stated already - it's impossible using just DNS. As a workaround I would suggest trying NGINX (http://nginx.org/en/docs/http/request_processing.html).
TL;DR - In NGINX you can create multiple virtual servers that can redirect your request based on the server name.
Ex. http://first.my-server.com redirect to place A and http://second.my-server.com redirect to place B, while both share a single physical server.
You can use htaccess rewrite mod, rewrite to the subfolder if the user is requesting one specific domain not the other.
Of course it is possible to redirect, with the following trick:
Create a new standard primary zone
Name it same as the fictive URL that you want to redirect to
Ensure that this fictive name is different than any AD DNS name
Create A record with following entries:
blank.......................A............................ip-addr-2
www.........................A............................ip-addr-2
What we have here is redirection, essentially. A valid URL will resolve based on the existing DNS primary DNS zone. A fictive URL will be redirected to ip-addr-2. What is important is that the name of this entry is blank, so it will fall down to the next entry in the record and redirect to ip-addr-2
Everyone has already stated this, and I just want to give you another option to a service that can help you. www.301redirect.it is a free service that can redirect your domain (with wildcard) to any destination url.
I want to add a disclosure as well: I'm the developer behind this service and there is a other options out there.

Resources